summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2008-10-03 03:39:52 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2008-10-03 03:39:52 +0000
commit7005a9a42fdf46fbd6925c995300c01ae56995f9 (patch)
treec255978ec18113d91e69fa166d7a35650cd2e161
parentabe17984fb608f62674737803ec0ea1012d5b176 (diff)
downloadsqlalchemy-7005a9a42fdf46fbd6925c995300c01ae56995f9.tar.gz
- Adjustment to Session's post-flush accounting of newly
"clean" objects to better protect against operating on objects as they're asynchronously gc'ed. [ticket:1182]
-rw-r--r--CHANGES4
-rw-r--r--lib/sqlalchemy/orm/session.py23
2 files changed, 16 insertions, 11 deletions
diff --git a/CHANGES b/CHANGES
index c129c0652..c5ddb1230 100644
--- a/CHANGES
+++ b/CHANGES
@@ -46,6 +46,10 @@ CHANGES
- Some adjustments to Session.identity_map's weak referencing
behavior to reduce asynchronous GC side effects.
+
+ - Adjustment to Session's post-flush accounting of newly
+ "clean" objects to better protect against operating on
+ objects as they're asynchronously gc'ed. [ticket:1182]
- sql
- column.in_(someselect) can now be used as a columns-clause
diff --git a/lib/sqlalchemy/orm/session.py b/lib/sqlalchemy/orm/session.py
index d4d512034..387f5a28d 100644
--- a/lib/sqlalchemy/orm/session.py
+++ b/lib/sqlalchemy/orm/session.py
@@ -1026,19 +1026,20 @@ class Session(object):
def _register_newly_persistent(self, state):
mapper = _state_mapper(state)
- instance_key = mapper._identity_key_from_state(state)
- if state.key is None:
- state.key = instance_key
- elif state.key != instance_key:
- # primary key switch
- self.identity_map.remove(state)
- state.key = instance_key
-
- obj = state.obj()
# prevent against last minute dereferences of the object
- # TODO: identify a code path where state.obj() is None
+ obj = state.obj()
if obj is not None:
+
+ instance_key = mapper._identity_key_from_state(state)
+
+ if state.key is None:
+ state.key = instance_key
+ elif state.key != instance_key:
+ # primary key switch
+ self.identity_map.remove(state)
+ state.key = instance_key
+
if state.key in self.identity_map and not self.identity_map.contains_state(state):
self.identity_map.remove_key(state.key)
self.identity_map.add(state)
@@ -1435,7 +1436,7 @@ class Session(object):
except:
transaction.rollback()
raise
-
+
flush_context.finalize_flush_changes()
if not objects: