summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/state.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2019-05-25 18:04:58 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2019-05-27 16:45:59 -0400
commite573752a986dec84216d948a1497b7d789d039ea (patch)
tree5c887df82321af54d1ccd445a16660fc0aa81707 /lib/sqlalchemy/orm/state.py
parent402da5f3f0bade44c2941ab8446f69cf33f5dd67 (diff)
downloadsqlalchemy-e573752a986dec84216d948a1497b7d789d039ea.tar.gz
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
Diffstat (limited to 'lib/sqlalchemy/orm/state.py')
-rw-r--r--lib/sqlalchemy/orm/state.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/lib/sqlalchemy/orm/state.py b/lib/sqlalchemy/orm/state.py
index c6252b6b8..f6c06acc8 100644
--- a/lib/sqlalchemy/orm/state.py
+++ b/lib/sqlalchemy/orm/state.py
@@ -311,6 +311,10 @@ class InstanceState(interfaces.InspectionAttrInfo):
return {}
@util.memoized_property
+ def _empty_collections(self):
+ return {}
+
+ @util.memoized_property
def mapper(self):
"""Return the :class:`.Mapper` used for this mapped object."""
return self.manager.mapper