From 0eab503a87475df65e0269a4a4855fb9d1bf5e9f Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Tue, 1 Sep 2009 22:55:59 +0000 Subject: - Fixed bug which prevented two entities from mutually replacing each other's primary key values within a single flush() for some orderings of operations. [ticket:1519] --- lib/sqlalchemy/orm/session.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/sqlalchemy/orm/session.py b/lib/sqlalchemy/orm/session.py index fdf679a42..002ccd509 100644 --- a/lib/sqlalchemy/orm/session.py +++ b/lib/sqlalchemy/orm/session.py @@ -1017,8 +1017,10 @@ class Session(object): if state.key is None: state.key = instance_key elif state.key != instance_key: - # primary key switch - self.identity_map.remove(state) + # primary key switch. + # use discard() in case another state has already replaced this + # one in the identity map (see test/orm/test_naturalpks.py ReversePKsTest) + self.identity_map.discard(state) state.key = instance_key self.identity_map.replace(state) -- cgit v1.2.1