summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/loading.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2017-08-23 16:33:10 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2017-08-23 17:20:17 -0400
commit827b495b8bc1c6c32ef7a872b7995abcb31a14d6 (patch)
tree3ee9c4af816195050f9c54be3ec51545a9fc036b /lib/sqlalchemy/orm/loading.py
parent3f9df2b86b4a8d7912d1190aead4aa084daf802c (diff)
downloadsqlalchemy-827b495b8bc1c6c32ef7a872b7995abcb31a14d6.tar.gz
Ensure col is not None when retrieving quick populators
Fixed bug where an :func:`.undefer_group` option would not be recognized if it extended from a relationship that was loading using joined eager loading. In particular we need to double check the column both in terms of the given "adapter" as well as without applying the "adapter" when searching for the column in the result. As we now avoid redoing the row processor step we also improve on callcounts in joined eager loading. Change-Id: I0f48766f12f7299f4626ff41a00bf1f5bfca5f3b Fixes: #4048
Diffstat (limited to 'lib/sqlalchemy/orm/loading.py')
-rw-r--r--lib/sqlalchemy/orm/loading.py19
1 files changed, 17 insertions, 2 deletions
diff --git a/lib/sqlalchemy/orm/loading.py b/lib/sqlalchemy/orm/loading.py
index e4aea3994..cbc995489 100644
--- a/lib/sqlalchemy/orm/loading.py
+++ b/lib/sqlalchemy/orm/loading.py
@@ -322,9 +322,24 @@ def _instance_processor(
# be present in some unexpected way.
populators["expire"].append((prop.key, False))
else:
+ getter = None
+ # the "adapter" can be here via different paths,
+ # e.g. via adapter present at setup_query or adapter
+ # applied to the query afterwards via eager load subquery.
+ # If the column here
+ # were already a product of this adapter, sending it through
+ # the adapter again can return a totally new expression that
+ # won't be recognized in the result, and the ColumnAdapter
+ # currently does not accommodate for this. OTOH, if the
+ # column were never applied through this adapter, we may get
+ # None back, in which case we still won't get our "getter".
+ # so try both against result._getter(). See issue #4048
if adapter:
- col = adapter.columns[col]
- getter = result._getter(col, False)
+ adapted_col = adapter.columns[col]
+ if adapted_col is not None:
+ getter = result._getter(adapted_col, False)
+ if not getter:
+ getter = result._getter(col, False)
if getter:
populators["quick"].append((prop.key, getter))
else: