diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-10-04 11:12:27 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-10-04 13:44:39 -0400 |
commit | 4aa43ecbd78e5a7dd3d983ca46a377af4e01877e (patch) | |
tree | 0e732b9e49ab686dce55b83b07d27c47e153d218 /lib/sqlalchemy/orm/identity.py | |
parent | edf8e782cf5011cd43a0ee281b9e0b1d1becef1f (diff) | |
download | sqlalchemy-4aa43ecbd78e5a7dd3d983ca46a377af4e01877e.tar.gz |
Warn for object replaced in identity map during flush
A warning is emitted for a condition in which the :class:`.Session` may
implicitly swap an object out of the identity map for another one with the
same primary key, detaching the old one, which can be an observed result of
load operations which occur within the :meth:`.SessionEvents.after_flush`
hook. The warning is intended to notify the user that some special
condition has caused this to happen and that the previous object may not be
in the expected state.
Fixes: #4890
Change-Id: Ide11c6b9f21ca67ff5a96266c521d0c56fd6af8d
Diffstat (limited to 'lib/sqlalchemy/orm/identity.py')
-rw-r--r-- | lib/sqlalchemy/orm/identity.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/sqlalchemy/orm/identity.py b/lib/sqlalchemy/orm/identity.py index 2da5d66b3..842b7915a 100644 --- a/lib/sqlalchemy/orm/identity.py +++ b/lib/sqlalchemy/orm/identity.py @@ -125,10 +125,13 @@ class WeakInstanceDict(IdentityMap): if existing is not state: self._manage_removed_state(existing) else: - return + return None + else: + existing = None self._dict[state.key] = state self._manage_incoming_state(state) + return existing def add(self, state): key = state.key @@ -297,9 +300,12 @@ class StrongInstanceDict(IdentityMap): self._manage_removed_state(existing) else: return + else: + existing = None self._dict[state.key] = state.obj() self._manage_incoming_state(state) + return existing def add(self, state): if state.key in self: |