diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-12-16 21:08:26 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-12-16 21:08:26 -0500 |
commit | f7f6fbede5b407b954ce20f9b55f7a02c4152aa9 (patch) | |
tree | e6a2fc172a6fe70ddcee8e4db3b39e264a19e2f8 /lib/sqlalchemy/orm/identity.py | |
parent | cd48a93318061c67572cffbe3d9f883d7326af8a (diff) | |
download | sqlalchemy-f7f6fbede5b407b954ce20f9b55f7a02c4152aa9.tar.gz |
- remove the need to use LoadDeferredColumns, LoadLazyAttribute in most cases,
these are back to being part of LoaderStrategy
- simplify attribute.get()
- inline the dict get inside of attribute.__get__()
- revert some memoized attrs from InstanceState which are called in almost
all cases regardless
- inlining
Diffstat (limited to 'lib/sqlalchemy/orm/identity.py')
-rw-r--r-- | lib/sqlalchemy/orm/identity.py | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/lib/sqlalchemy/orm/identity.py b/lib/sqlalchemy/orm/identity.py index 8604c0008..f1400a8c6 100644 --- a/lib/sqlalchemy/orm/identity.py +++ b/lib/sqlalchemy/orm/identity.py @@ -121,17 +121,28 @@ class WeakInstanceDict(IdentityMap): dict.__setitem__(self, state.key, state) self._manage_incoming_state(state) - + 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, )) - else: - dict.__setitem__(self, state.key, state) - self._manage_incoming_state(state) - + key = state.key + # inline of self.__contains__ + if dict.__contains__(self, key): + try: + existing_state = dict.__getitem__(self, key) + if existing_state is not state: + o = existing_state.obj() + if o is None: + o = existing_state._is_really_none() + if o is not None: + raise AssertionError("A conflicting state is already " + "present in the identity map for key %r" + % (key, )) + else: + return + except KeyError: + pass + dict.__setitem__(self, key, state) + self._manage_incoming_state(state) + def remove_key(self, key): state = dict.__getitem__(self, key) self.remove(state) |