]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Note for history methods that history is reset per-flush.
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 9 Feb 2019 17:22:39 +0000 (12:22 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 9 Feb 2019 17:22:39 +0000 (12:22 -0500)
Change-Id: I9bc4d0ddfa93f13e6717b89fa9934f1b8052147f

lib/sqlalchemy/orm/attributes.py
lib/sqlalchemy/orm/state.py

index 879b88a928675e78a3fc234ad526bc2d110e05ff..1b8c8c7f33d4cf0e4d616e2c8453001c83b8bf49 100644 (file)
@@ -1724,6 +1724,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.
 
@@ -1735,6 +1746,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(
index 38c3f3791f870ac2504978e0e58b5a9b4645b0fe..c6252b6b8cae7b94c63a1a84599b99289f656363 100644 (file)
@@ -880,12 +880,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
@@ -897,12 +906,20 @@ class AttributeState(object):
         return self.state.get_history(self.key, 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`