diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-02-14 11:39:44 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-03-15 17:22:59 -0400 |
| commit | 2bfe19152d49b969acdc4607bf7c33727f796f5a (patch) | |
| tree | 0f71aa7ac14459bb03f1b6ced1c66741d90a9232 /lib | |
| parent | b5b6e9574854fd9784d7c26e2c585a3ff5ae4cb6 (diff) | |
| download | sqlalchemy-2bfe19152d49b969acdc4607bf7c33727f796f5a.tar.gz | |
Don't mutate old collection on bulk replace
For a bulk replace, assume the old collection is no longer
useful to the attribute system and only send the removal events,
not actually mutated the collection.
this changes behavior significantly and also means that dispose_collection
now receives the old collection intact.
Change-Id: Ic2685c85438191f07797d9ef97833a2cfdc4fcc2
Fixes: #3913
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/sqlalchemy/orm/collections.py | 3 | ||||
| -rw-r--r-- | lib/sqlalchemy/orm/events.py | 8 |
2 files changed, 7 insertions, 4 deletions
diff --git a/lib/sqlalchemy/orm/collections.py b/lib/sqlalchemy/orm/collections.py index 2bb53e61e..d949dc8a1 100644 --- a/lib/sqlalchemy/orm/collections.py +++ b/lib/sqlalchemy/orm/collections.py @@ -764,9 +764,8 @@ def bulk_replace(values, existing_adapter, new_adapter): appender(member, _sa_initiator=False) if existing_adapter: - remover = existing_adapter.bulk_remover() for member in removals: - remover(member) + existing_adapter.fire_remove_event(member) def prepare_instrumentation(factory): diff --git a/lib/sqlalchemy/orm/events.py b/lib/sqlalchemy/orm/events.py index d2ccec432..ceeb31e9c 100644 --- a/lib/sqlalchemy/orm/events.py +++ b/lib/sqlalchemy/orm/events.py @@ -2124,8 +2124,12 @@ class AttributeEvents(event.Events): u1.addresses = [a2, a3] # <- old collection is disposed - The mechanics of the event will typically include that the given - collection is empty, even if it stored objects while being replaced. + The old collection received will contain its previous contents. + + .. versionchanged:: 1.2 The collection passed to + :meth:`.AttributeEvents.dispose_collection` will now have its + contents before the dispose intact; previously, the collection + would be empty. .. versionadded:: 1.0.0 the :meth:`.AttributeEvents.init_collection` and :meth:`.AttributeEvents.dispose_collection` events supersede |
