]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Adjustment to Session's post-flush accounting of newly
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 3 Oct 2008 03:39:52 +0000 (03:39 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 3 Oct 2008 03:39:52 +0000 (03:39 +0000)
"clean" objects to better protect against operating on
objects as they're asynchronously gc'ed. [ticket:1182]

CHANGES
lib/sqlalchemy/orm/session.py

diff --git a/CHANGES b/CHANGES
index c129c065292da70162d68c0ef9fa738ef69511d7..c5ddb123014af49013097ee915ff719b5180db3b 100644 (file)
--- 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
index d4d512034ed01d361b1c1b14ef99c07723b4d048..387f5a28d64381a31450e5ae13bb082f5e8abd9a 100644 (file)
@@ -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: