summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/session.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2013-04-20 02:45:08 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2013-04-20 02:45:08 -0400
commit6c1972e4ecd7f2d738aa1578bc95d4a77820278d (patch)
treeb65f3b060672c1adda23a0bacaff41e6b5f626e0 /lib/sqlalchemy/orm/session.py
parent15b3d2f5bd3ff24b06945a3243eef0d3f523db15 (diff)
downloadsqlalchemy-6c1972e4ecd7f2d738aa1578bc95d4a77820278d.tar.gz
Improved the behavior of instance management regarding
the creation of strong references within the Session; an object will no longer have an internal reference cycle created if it's in the transient state or moves into the detached state - the strong ref is created only when the object is attached to a Session and is removed when the object is detached. This makes it somewhat safer for an object to have a `__del__()` method, even though this is not recommended, as relationships with backrefs produce cycles too. A warning has been added when a class with a `__del__()` method is mapped. [ticket:2708]
Diffstat (limited to 'lib/sqlalchemy/orm/session.py')
-rw-r--r--lib/sqlalchemy/orm/session.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/sqlalchemy/orm/session.py b/lib/sqlalchemy/orm/session.py
index 408b119a0..361ab65e6 100644
--- a/lib/sqlalchemy/orm/session.py
+++ b/lib/sqlalchemy/orm/session.py
@@ -1727,13 +1727,13 @@ class Session(_SessionClassMethods):
def _before_attach(self, state):
if state.session_id != self.hash_key and \
- self.dispatch.before_attach:
+ self.dispatch.before_attach:
self.dispatch.before_attach(self, state.obj())
def _attach(self, state, include_before=False):
if state.key and \
state.key in self.identity_map and \
- not self.identity_map.contains_state(state):
+ not self.identity_map.contains_state(state):
raise sa_exc.InvalidRequestError("Can't attach instance "
"%s; another instance with key %s is already "
"present in this session."
@@ -1749,9 +1749,11 @@ class Session(_SessionClassMethods):
if state.session_id != self.hash_key:
if include_before and \
- self.dispatch.before_attach:
+ self.dispatch.before_attach:
self.dispatch.before_attach(self, state.obj())
state.session_id = self.hash_key
+ if state.modified and not state._strong_obj:
+ state._strong_obj = state.obj()
if self.dispatch.after_attach:
self.dispatch.after_attach(self, state.obj())