summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2016-10-27 09:51:50 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2016-10-27 09:51:50 -0400
commite56a9d85acd165cfea08f9dc7e9d747054ce6fdb (patch)
tree9b4945ac54be816787e58f9fe8745ef56e0a7690 /lib/sqlalchemy
parent1f32d014da5d40406cd5d3996be5283c2fc57b26 (diff)
downloadsqlalchemy-e56a9d85acd165cfea08f9dc7e9d747054ce6fdb.tar.gz
Restore object to the identity_map upon delete() unconditionally
Fixed regression caused by :ticket:`2677` whereby calling :meth:`.Session.delete` on an object that was already flushed as deleted in that session would fail to set up the object in the identity map (or reject the object), causing flush errors as the object were in a state not accommodated by the unit of work. The pre-1.1 behavior in this case has been restored, which is that the object is put back into the identity map so that the DELETE statement will be attempted again, which emits a warning that the number of expected rows was not matched (unless the row were restored outside of the session). Change-Id: I9a8871f82cb1ebe67a7ad54d888d5ee835a9a40a Fixes: #3839
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/orm/session.py9
-rw-r--r--lib/sqlalchemy/orm/unitofwork.py3
2 files changed, 9 insertions, 3 deletions
diff --git a/lib/sqlalchemy/orm/session.py b/lib/sqlalchemy/orm/session.py
index b492cbb7f..b39ba1465 100644
--- a/lib/sqlalchemy/orm/session.py
+++ b/lib/sqlalchemy/orm/session.py
@@ -1726,8 +1726,9 @@ class Session(_SessionClassMethods):
if state in self._deleted:
return
+ self.identity_map.add(state)
+
if to_attach:
- self.identity_map.add(state)
self._after_attach(state, obj)
if head:
@@ -2196,7 +2197,8 @@ class Session(_SessionClassMethods):
for state in proc:
is_orphan = (
_state_mapper(state)._is_orphan(state) and state.has_identity)
- flush_context.register_object(state, isdelete=is_orphan)
+ _reg = flush_context.register_object(state, isdelete=is_orphan)
+ assert _reg, "Failed to add object to the flush context!"
processed.add(state)
# put all remaining deletes into the flush context.
@@ -2205,7 +2207,8 @@ class Session(_SessionClassMethods):
else:
proc = deleted.difference(processed)
for state in proc:
- flush_context.register_object(state, isdelete=True)
+ _reg = flush_context.register_object(state, isdelete=True)
+ assert _reg, "Failed to add object to the flush context!"
if not flush_context.has_work:
return
diff --git a/lib/sqlalchemy/orm/unitofwork.py b/lib/sqlalchemy/orm/unitofwork.py
index f3e39d9b5..de4842d6f 100644
--- a/lib/sqlalchemy/orm/unitofwork.py
+++ b/lib/sqlalchemy/orm/unitofwork.py
@@ -242,6 +242,9 @@ class UOWTransaction(object):
listonly=False, cancel_delete=False,
operation=None, prop=None):
if not self.session._contains_state(state):
+ # this condition is normal when objects are registered
+ # as part of a relationship cascade operation. it should
+ # not occur for the top-level register from Session.flush().
if not state.deleted and operation is not None:
util.warn("Object of type %s not in session, %s operation "
"along '%s' will not proceed" %