diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-05-03 09:55:12 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-05-03 12:30:19 -0400 |
commit | 216de6e7ceb893200fcde6b158c51180866f4004 (patch) | |
tree | 54b2dd3029426621455196b95eb58557cbf4c5ac /lib/sqlalchemy/orm/dynamic.py | |
parent | ee7a82d71783bf71f3a95550624740e908d178a0 (diff) | |
download | sqlalchemy-216de6e7ceb893200fcde6b158c51180866f4004.tar.gz |
loader strategy regression fixes
Fixed regression where using :func:`_orm.selectinload` and
:func:`_orm.subqueryload` to load a two-level-deep path would lead to an
attribute error.
Fixed regression where using the :func:`_orm.noload` loader strategy in
conjunction with a "dynamic" relationship would lead to an attribute error
as the noload strategy would attempt to apply itself to the dynamic loader.
Fixes: #6419
Fixes: #6420
Change-Id: I933b208f16a9723f6ebeab7addbe118903a1f8f5
Diffstat (limited to 'lib/sqlalchemy/orm/dynamic.py')
-rw-r--r-- | lib/sqlalchemy/orm/dynamic.py | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/lib/sqlalchemy/orm/dynamic.py b/lib/sqlalchemy/orm/dynamic.py index bf8fc0e33..a4b5f58c7 100644 --- a/lib/sqlalchemy/orm/dynamic.py +++ b/lib/sqlalchemy/orm/dynamic.py @@ -105,10 +105,11 @@ class DynamicAttributeImpl(attributes.AttributeImpl): passive=attributes.PASSIVE_NO_INITIALIZE, ): if not passive & attributes.SQL_OK: - return self._get_collection_history(state, passive).added_items + data = self._get_collection_history(state, passive).added_items else: history = self._get_collection_history(state, passive) - return history.added_plus_unchanged + data = history.added_plus_unchanged + return DynamicCollectionAdapter(data) @util.memoized_property def _append_token(self): @@ -259,6 +260,27 @@ class DynamicAttributeImpl(attributes.AttributeImpl): self.remove(state, dict_, value, initiator, passive=passive) +class DynamicCollectionAdapter(object): + """simplified CollectionAdapter for internal API consistency""" + + def __init__(self, data): + self.data = data + + def __iter__(self): + return iter(self.data) + + def _reset_empty(self): + pass + + def __len__(self): + return len(self.data) + + def __bool__(self): + return True + + __nonzero__ = __bool__ + + class AppenderMixin(object): query_class = None |