]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- repair documenation for object_session(), returns None if no
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 19 Oct 2014 20:56:18 +0000 (16:56 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 19 Oct 2014 20:56:18 +0000 (16:56 -0400)
session, and refer to InstanceState.session.  Add note about
objects that are deleted within an ongoing transaction.

lib/sqlalchemy/orm/session.py
lib/sqlalchemy/orm/state.py

index dd82fa02f34d9c1a39fcef9df64fd113373ae475..f5c52a6adad649b6b7918a92636c69e41663ca1b 100644 (file)
@@ -2443,16 +2443,17 @@ def make_transient_to_detached(instance):
 
 
 def object_session(instance):
-    """Return the ``Session`` to which instance belongs.
+    """Return the :class:`.Session` to which the given instance belongs.
 
-    If the instance is not a mapped instance, an error is raised.
+    This is essentially the same as the :attr:`.InstanceState.session`
+    accessor.  See that attribute for details.
 
     """
-
     try:
-        return _state_session(attributes.instance_state(instance))
+        state = attributes.instance_state(instance)
     except exc.NO_STATE:
         raise exc.UnmappedInstanceError(instance)
-
+    else:
+        return _state_session(state)
 
 _new_sessionid = util.counter()
index b9aff7a853a0b8aae25fbf43240bb73e31bd01e0..c41a3c869a6b4c82cb85000cb0db016486422bc2 100644 (file)
@@ -146,7 +146,16 @@ class InstanceState(interfaces._InspectionAttr):
     @util.dependencies("sqlalchemy.orm.session")
     def session(self, sessionlib):
         """Return the owning :class:`.Session` for this instance,
-        or ``None`` if none available."""
+        or ``None`` if none available.
+
+        Note that the result here can in some cases be *different*
+        from that of ``obj in session``; an object that's been deleted
+        will report as not ``in session``, however if the transaction is
+        still in progress, this attribute will still refer to that session.
+        Only when the transaction is completed does the object become
+        fully detached under normal circumstances.
+
+        """
         return sessionlib._state_session(self)
 
     @property