From 3aefc6e8a4a02892de91bdac9a917d1697c90ea6 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 16 Jan 2017 12:10:08 -0500 Subject: 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 --- lib/sqlalchemy/orm/strategies.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'lib') 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)) -- cgit v1.2.1