diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2008-10-03 03:39:52 +0000 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2008-10-03 03:39:52 +0000 |
| commit | 7005a9a42fdf46fbd6925c995300c01ae56995f9 (patch) | |
| tree | c255978ec18113d91e69fa166d7a35650cd2e161 /lib/sqlalchemy | |
| parent | abe17984fb608f62674737803ec0ea1012d5b176 (diff) | |
| download | sqlalchemy-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]
Diffstat (limited to 'lib/sqlalchemy')
| -rw-r--r-- | lib/sqlalchemy/orm/session.py | 23 |
1 files changed, 12 insertions, 11 deletions
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: |
