]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
Hold implicitly created collections in a pending area
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 25 May 2019 22:04:58 +0000 (18:04 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 27 May 2019 20:45:59 +0000 (16:45 -0400)
commite573752a986dec84216d948a1497b7d789d039ea
tree5c887df82321af54d1ccd445a16660fc0aa81707
parent402da5f3f0bade44c2941ab8446f69cf33f5dd67
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
12 files changed:
doc/build/changelog/migration_14.rst
doc/build/changelog/unreleased_14/4519.rst [new file with mode: 0644]
lib/sqlalchemy/orm/attributes.py
lib/sqlalchemy/orm/collections.py
lib/sqlalchemy/orm/events.py
lib/sqlalchemy/orm/relationships.py
lib/sqlalchemy/orm/state.py
lib/sqlalchemy/orm/strategies.py
test/orm/test_attributes.py
test/orm/test_collection.py
test/orm/test_inspect.py
test/orm/test_merge.py