diff options
author | mike bayer <mike_mp@zzzcomputing.com> | 2019-02-10 03:57:10 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@bbpush.zzzcomputing.com> | 2019-02-10 03:57:10 +0000 |
commit | bb7b353d6f97184d2689c8c682bab5caac4ec1e7 (patch) | |
tree | 3345a63858960deabb5814747f3addec0599cb41 /lib/sqlalchemy | |
parent | 833583458c69e24e797c300c934da0ff04348db5 (diff) | |
parent | b2afef966dcc44e991f22a8fb68de4f1220bd674 (diff) | |
download | sqlalchemy-bb7b353d6f97184d2689c8c682bab5caac4ec1e7.tar.gz |
Merge "Don't run pending_to_persistent for non-new objects"
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r-- | lib/sqlalchemy/orm/session.py | 14 | ||||
-rw-r--r-- | lib/sqlalchemy/orm/unitofwork.py | 2 |
2 files changed, 13 insertions, 3 deletions
diff --git a/lib/sqlalchemy/orm/session.py b/lib/sqlalchemy/orm/session.py index 6d4198a4e..0b1a3b101 100644 --- a/lib/sqlalchemy/orm/session.py +++ b/lib/sqlalchemy/orm/session.py @@ -1827,7 +1827,14 @@ class Session(_SessionClassMethods): states, self, to_transient=to_transient ) - def _register_newly_persistent(self, states): + def _register_persistent(self, states): + """Register all persistent objects from a flush. + + This is used both for pending objects moving to the persistent + state as well as already persistent objects. + + """ + pending_to_persistent = self.dispatch.pending_to_persistent or None for state in states: mapper = _state_mapper(state) @@ -1871,6 +1878,9 @@ class Session(_SessionClassMethods): ) state.key = instance_key + # there can be an existing state in the identity map + # that is replaced when the primary keys of two instances + # are swapped; see test/orm/test_naturalpks.py -> test_reverse self.identity_map.replace(state) state._orphaned_outside_of_session = False @@ -1881,7 +1891,7 @@ class Session(_SessionClassMethods): self._register_altered(states) if pending_to_persistent is not None: - for state in states: + for state in states.intersection(self._new): pending_to_persistent(self, state.obj()) # remove from new last, might be the last strong ref diff --git a/lib/sqlalchemy/orm/unitofwork.py b/lib/sqlalchemy/orm/unitofwork.py index 3b91c8990..1f2221ea9 100644 --- a/lib/sqlalchemy/orm/unitofwork.py +++ b/lib/sqlalchemy/orm/unitofwork.py @@ -440,7 +440,7 @@ class UOWTransaction(object): if isdel: self.session._remove_newly_deleted(isdel) if other: - self.session._register_newly_persistent(other) + self.session._register_persistent(other) class IterateMappersMixin(object): |