From e573752a986dec84216d948a1497b7d789d039ea Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 25 May 2019 18:04:58 -0400 Subject: Hold implicitly created collections in a pending area Accessing a collection-oriented attribute on a newly created object no longer mutates ``__dict__``, but still returns an empty collection as has always been the case. This allows collection-oriented attributes to work consistently in comparison to scalar attributes which return ``None``, but also don't mutate ``__dict__``. In order to accommodate for the collection being mutated, the same empty collection is returned each time once initially created, and when it is mutated (e.g. an item appended, added, etc.) it is then moved into ``__dict__``. This removes the last of mutating side-effects on read-only attribute access within the ORM. Fixes: #4519 Change-Id: I06a058d24e6eb24b5c6b6092d3f8b31cf9c244ae --- lib/sqlalchemy/orm/events.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'lib/sqlalchemy/orm/events.py') diff --git a/lib/sqlalchemy/orm/events.py b/lib/sqlalchemy/orm/events.py index d73a20e93..5bf6ff418 100644 --- a/lib/sqlalchemy/orm/events.py +++ b/lib/sqlalchemy/orm/events.py @@ -2267,6 +2267,9 @@ class AttributeEvents(event.Events): .. seealso:: + :meth:`.AttributeEvents.init_collection` - collection version + of this event + :class:`.AttributeEvents` - background on listener options such as propagation to subclasses. @@ -2312,6 +2315,9 @@ class AttributeEvents(event.Events): :class:`.AttributeEvents` - background on listener options such as propagation to subclasses. + :meth:`.AttributeEvents.init_scalar` - "scalar" version of this + event. + """ def dispose_collection(self, target, collection, collection_adapter): -- cgit v1.2.1