diff options
Diffstat (limited to 'lib/sqlalchemy/orm/strategies.py')
| -rw-r--r-- | lib/sqlalchemy/orm/strategies.py | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/sqlalchemy/orm/strategies.py b/lib/sqlalchemy/orm/strategies.py index 4e3574b54..ffd47d17d 100644 --- a/lib/sqlalchemy/orm/strategies.py +++ b/lib/sqlalchemy/orm/strategies.py @@ -851,11 +851,14 @@ class SubqueryLoader(AbstractRelationshipLoader): # set a real "from" if not present, as this is more # accurate than just going off of the column expression - if not q._from_obj and orig_entity.mapper.isa(leftmost_mapper): + if not q._from_obj and orig_entity.is_mapper and \ + orig_entity.mapper.isa(leftmost_mapper): q._set_select_from([orig_entity], False) target_cols = q._adapt_col_list(leftmost_attr) - # select from the identity columns of the outer + # select from the identity columns of the outer. This will remove + # other columns from the query that might suggest the right entity + # which is why we try to _set_select_from above. q._set_entities(target_cols) distinct_target_key = leftmost_relationship.distinct_target_key |
