summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2019-02-09 12:22:39 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2019-02-09 12:23:20 -0500
commit2baecc0c134393ce1e1e3a5754c889977dce7e30 (patch)
tree1afdd08fa57ef94afc63ab8124b2c692b23455e5
parent48889aae38ae5a995b965089b066023db0a0573b (diff)
downloadsqlalchemy-2baecc0c134393ce1e1e3a5754c889977dce7e30.tar.gz
Note for history methods that history is reset per-flush.
Change-Id: I9bc4d0ddfa93f13e6717b89fa9934f1b8052147f (cherry picked from commit 833583458c69e24e797c300c934da0ff04348db5)
-rw-r--r--lib/sqlalchemy/orm/attributes.py18
-rw-r--r--lib/sqlalchemy/orm/state.py21
2 files changed, 37 insertions, 2 deletions
diff --git a/lib/sqlalchemy/orm/attributes.py b/lib/sqlalchemy/orm/attributes.py
index f19a05255..445d9f417 100644
--- a/lib/sqlalchemy/orm/attributes.py
+++ b/lib/sqlalchemy/orm/attributes.py
@@ -1397,6 +1397,17 @@ def get_history(obj, key, passive=PASSIVE_OFF):
"""Return a :class:`.History` record for the given object
and attribute key.
+ This is the **pre-flush** history for a given attribute, which is
+ reset each time the :class:`.Session` flushes changes to the
+ current database transaction.
+
+ .. note::
+
+ Prefer to use the :attr:`.AttributeState.history` and
+ :meth:`.AttributeState.load_history` accessors to retrieve the
+ :class:`.History` for instance attributes.
+
+
:param obj: an object whose class is instrumented by the
attributes package.
@@ -1408,6 +1419,13 @@ def get_history(obj, key, passive=PASSIVE_OFF):
:attr:`.PASSIVE_OFF` indicating all necessary SQL
should be emitted.
+ .. seealso::
+
+ :attr:`.AttributeState.history`
+
+ :meth:`.AttributeState.load_history` - retrieve history
+ using loader callables if the value is not locally present.
+
"""
if passive is True:
util.warn_deprecated("Passing True for 'passive' is deprecated. "
diff --git a/lib/sqlalchemy/orm/state.py b/lib/sqlalchemy/orm/state.py
index 67e58bb53..ed092f130 100644
--- a/lib/sqlalchemy/orm/state.py
+++ b/lib/sqlalchemy/orm/state.py
@@ -666,12 +666,21 @@ class AttributeState(object):
@property
def history(self):
- """Return the current pre-flush change history for
+ """Return the current **pre-flush** change history for
this attribute, via the :class:`.History` interface.
This method will **not** emit loader callables if the value of the
attribute is unloaded.
+ .. note::
+
+ The attribute history system tracks changes on a **per flush
+ basis**. Each time the :class:`.Session` is flushed, the history
+ of each attribute is reset to empty. The :class:`.Session` by
+ default autoflushes each time a :class:`.Query` is invoked. For
+ options on how to control this, see :ref:`session_flushing`.
+
+
.. seealso::
:meth:`.AttributeState.load_history` - retrieve history
@@ -684,12 +693,20 @@ class AttributeState(object):
PASSIVE_NO_INITIALIZE)
def load_history(self):
- """Return the current pre-flush change history for
+ """Return the current **pre-flush** change history for
this attribute, via the :class:`.History` interface.
This method **will** emit loader callables if the value of the
attribute is unloaded.
+ .. note::
+
+ The attribute history system tracks changes on a **per flush
+ basis**. Each time the :class:`.Session` is flushed, the history
+ of each attribute is reset to empty. The :class:`.Session` by
+ default autoflushes each time a :class:`.Query` is invoked. For
+ options on how to control this, see :ref:`session_flushing`.
+
.. seealso::
:attr:`.AttributeState.history`