summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/unitofwork.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2021-05-12 09:26:03 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2021-05-12 09:26:03 -0400
commit71a858817cb8c11451ae577c61329f4239fab46b (patch)
tree14fcd7fa0facf6f772280e0aea42d7124aeca509 /lib/sqlalchemy/orm/unitofwork.py
parentf6329060f1b2f5631deac3ca877c2ae19e3e6f36 (diff)
downloadsqlalchemy-71a858817cb8c11451ae577c61329f4239fab46b.tar.gz
Create new event for collection add w/o mutation
Fixed issue when using :paramref:`_orm.relationship.cascade_backrefs` parameter set to ``False``, which per :ref:`change_5150` is set to become the standard behavior in SQLAlchemy 2.0, where adding the item to a collection that uniquifies, such as ``set`` or ``dict`` would fail to fire a cascade event if the object were already associated in that collection via the backref. This fix represents a fundamental change in the collection mechanics by introducing a new event state which can fire off for a collection mutation even if there is no net change on the collection; the action is now suited using a new event hook :meth:`_orm.AttributeEvents.append_wo_mutation`. Fixes: #6471 Change-Id: Ic50413f7e62440dad33ab84838098ea62ff4e815
Diffstat (limited to 'lib/sqlalchemy/orm/unitofwork.py')
-rw-r--r--lib/sqlalchemy/orm/unitofwork.py1
1 files changed, 1 insertions, 0 deletions
diff --git a/lib/sqlalchemy/orm/unitofwork.py b/lib/sqlalchemy/orm/unitofwork.py
index 77bbb4751..ae99da059 100644
--- a/lib/sqlalchemy/orm/unitofwork.py
+++ b/lib/sqlalchemy/orm/unitofwork.py
@@ -144,6 +144,7 @@ def track_cascade_events(descriptor, prop):
sess.expunge(oldvalue)
return newvalue
+ event.listen(descriptor, "append_wo_mutation", append, raw=True)
event.listen(descriptor, "append", append, raw=True, retval=True)
event.listen(descriptor, "remove", remove, raw=True, retval=True)
event.listen(descriptor, "set", set_, raw=True, retval=True)