diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2009-08-31 21:53:49 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2009-08-31 21:53:49 +0000 |
commit | 2cb92cbbd0dda5646c98ddb29592064221740753 (patch) | |
tree | e913441b1ab397c9180520f64972406493065dbd /lib/sqlalchemy/orm/identity.py | |
parent | 358ab55c311a823c241a5ae87806cb2607e5e1f1 (diff) | |
download | sqlalchemy-2cb92cbbd0dda5646c98ddb29592064221740753.tar.gz |
- Fixed incorrect exception raise in
Weak/StrongIdentityMap.add()
[ticket:1506]
Diffstat (limited to 'lib/sqlalchemy/orm/identity.py')
-rw-r--r-- | lib/sqlalchemy/orm/identity.py | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/lib/sqlalchemy/orm/identity.py b/lib/sqlalchemy/orm/identity.py index 889b65ba7..d0d0a7962 100644 --- a/lib/sqlalchemy/orm/identity.py +++ b/lib/sqlalchemy/orm/identity.py @@ -121,7 +121,7 @@ class WeakInstanceDict(IdentityMap): def add(self, state): if state.key in self: if dict.__getitem__(self, state.key) is not state: - raise AssertionError("A conflicting state is already present in the identity map for key %r" % state.key) + raise AssertionError("A conflicting state is already present in the identity map for key %r" % (state.key, )) else: dict.__setitem__(self, state.key, state) self._manage_incoming_state(state) @@ -208,11 +208,15 @@ class StrongInstanceDict(IdentityMap): dict.__setitem__(self, state.key, state.obj()) self._manage_incoming_state(state) - + def add(self, state): - dict.__setitem__(self, state.key, state.obj()) - self._manage_incoming_state(state) - + if state.key in self: + if dict.__getitem__(self, state.key) is not state: + raise AssertionError("A conflicting state is already present in the identity map for key %r" % (state.key, )) + else: + dict.__setitem__(self, state.key, state.obj()) + self._manage_incoming_state(state) + def remove(self, state): if attributes.instance_state(dict.pop(self, state.key)) is not state: raise AssertionError("State %s is not present in this identity map" % state) |