summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/identity.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqlalchemy/orm/identity.py')
-rw-r--r--lib/sqlalchemy/orm/identity.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/sqlalchemy/orm/identity.py b/lib/sqlalchemy/orm/identity.py
index 7eec4fd8d..6aea0d185 100644
--- a/lib/sqlalchemy/orm/identity.py
+++ b/lib/sqlalchemy/orm/identity.py
@@ -18,6 +18,9 @@ class IdentityMap(object):
self._modified = set()
self._wr = weakref.ref(self)
+ def _kill(self):
+ self._add_unpresent = _killed
+
def keys(self):
return self._dict.keys()
@@ -238,3 +241,14 @@ class WeakInstanceDict(IdentityMap):
if st is state:
self._dict.pop(state.key, None)
self._manage_removed_state(state)
+
+
+def _killed(state, key):
+ # external function to avoid creating cycles when assigned to
+ # the IdentityMap
+ raise sa_exc.InvalidRequestError(
+ "Object %s cannot be converted to 'persistent' state, as this "
+ "identity map is no longer valid. Has the owning Session "
+ "been closed?" % orm_util.state_str(state),
+ code="lkrp",
+ )