diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-01-16 12:10:08 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-01-16 13:16:25 -0500 |
| commit | 3aefc6e8a4a02892de91bdac9a917d1697c90ea6 (patch) | |
| tree | 0f06fa7e2831d266142f4d831de8f62979eca9ec /lib | |
| parent | 710ce4aaf9130cce0ad17cc471be57038dd641aa (diff) | |
| download | sqlalchemy-3aefc6e8a4a02892de91bdac9a917d1697c90ea6.tar.gz | |
Add "existing" populators for subqueryload
Fixed bug in subquery loading where an object encountered as an
"existing" row, e.g. already loaded from a different path in the
same query, would not invoke subquery loaders for unloaded attributes
that specified this loading. This issue is in the same area
as that of :ticket:`3431`, :ticket:`3811` which involved
similar issues with joined loading.
Change-Id: If111a76b0812010905b0ac811276a816779d297f
Fixes: #3854
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/sqlalchemy/orm/strategies.py | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/lib/sqlalchemy/orm/strategies.py b/lib/sqlalchemy/orm/strategies.py index ace82871f..4e3574b54 100644 --- a/lib/sqlalchemy/orm/strategies.py +++ b/lib/sqlalchemy/orm/strategies.py @@ -1087,7 +1087,15 @@ class SubqueryLoader(AbstractRelationshipLoader): state.get_impl(self.key).\ set_committed_value(state, dict_, collection) - populators["new"].append((self.key, load_collection_from_subq)) + def load_collection_from_subq_existing_row(state, dict_, row): + if self.key not in dict_: + load_collection_from_subq(state, dict_, row) + + populators["new"].append( + (self.key, load_collection_from_subq)) + populators["existing"].append( + (self.key, load_collection_from_subq_existing_row)) + if context.invoke_all_eagers: populators["eager"].append((self.key, collections.loader)) @@ -1108,7 +1116,14 @@ class SubqueryLoader(AbstractRelationshipLoader): state.get_impl(self.key).\ set_committed_value(state, dict_, scalar) - populators["new"].append((self.key, load_scalar_from_subq)) + def load_scalar_from_subq_existing_row(state, dict_, row): + if self.key not in dict_: + load_scalar_from_subq(state, dict_, row) + + populators["new"].append( + (self.key, load_scalar_from_subq)) + populators["existing"].append( + (self.key, load_scalar_from_subq_existing_row)) if context.invoke_all_eagers: populators["eager"].append((self.key, collections.loader)) |
