return list(self._dict.values())
def discard(self, state):
+ st = self._dict.pop(state.key, None)
+ if st:
+ assert st is state
+ self._manage_removed_state(state)
+
+ def safe_discard(self, state):
if state.key in self._dict:
st = self._dict[state.key]
if st is state:
state._instance_dict = self._wr
def discard(self, state):
+ obj = self._dict.pop(state.key, None)
+ if obj is not None:
+ self._manage_removed_state(state)
+ st = attributes.instance_state(obj)
+ assert st is state
+
+ def safe_discard(self, state):
if state.key in self._dict:
obj = self._dict[state.key]
st = attributes.instance_state(obj)
if state.key is None:
state.key = instance_key
elif state.key != instance_key:
- # primary key switch. use discard() in case another
+ # primary key switch. use safe_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)
+ self.identity_map.safe_discard(state)
if state in self.transaction._key_switches:
orig_key = self.transaction._key_switches[state][0]
else:
expired = False
deleted = False
_load_pending = False
-
is_instance = True
def __init__(self, obj, manager):
def _cleanup(self, ref):
instance_dict = self._instance_dict()
- if instance_dict:
+ if instance_dict is not None:
instance_dict.discard(self)
self.callables.clear()