summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/attributes.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2018-12-27 22:10:45 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2018-12-28 08:37:03 -0500
commit07cea66ccb74c68fa505b5fbba91984e0375993d (patch)
tree9b62f3292aa727763ccc326f000cefb9692adb63 /lib/sqlalchemy/orm/attributes.py
parentec5c9ebe6e7b8822de0c7bd19aea11ea2a582e29 (diff)
downloadsqlalchemy-07cea66ccb74c68fa505b5fbba91984e0375993d.tar.gz
Call __del() before remove()
The "remove" event for collections is now called before the item is removed in the case of the ``collection.remove()`` method, as is consistent with the behavior for most other forms of collection item removal (such as ``__delitem__``, replacement under ``__setitem__``). The ``pop()`` methods are now the only exception as the target item is not available until after the pop operation proceeds. This allows ``remove()`` to be consistent in its behavior with all the other collection operations, allows the "before_delete" hook to be local to "pop()" operations only, and removes some method overhead. We are also looking here to gain some more predictability in terms of the fix for #1103. Change-Id: I4fdea911517d65cc300fae0e9c351a471e52e4ab
Diffstat (limited to 'lib/sqlalchemy/orm/attributes.py')
-rw-r--r--lib/sqlalchemy/orm/attributes.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/sqlalchemy/orm/attributes.py b/lib/sqlalchemy/orm/attributes.py
index ff730d745..5ba8be439 100644
--- a/lib/sqlalchemy/orm/attributes.py
+++ b/lib/sqlalchemy/orm/attributes.py
@@ -973,6 +973,14 @@ class CollectionAttributeImpl(AttributeImpl):
return value
def fire_pre_remove_event(self, state, dict_, initiator):
+ """A special event used for pop() operations.
+
+ The "remove" event needs to have the item to be removed passed to
+ it, which in the case of pop from a set, we don't have a way to access
+ the item before the operation. the event is used for all pop()
+ operations (even though set.pop is the one where it is really needed).
+
+ """
state._modified_event(dict_, self, NEVER_SET, True)
def fire_remove_event(self, state, dict_, value, initiator):