diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2018-04-19 17:07:32 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2018-04-19 17:11:47 -0400 |
| commit | 4f2d0913fe4fe4f5182f85903a6b3be65ac4fd94 (patch) | |
| tree | 23fc97a6378b880a5d58669bd8bae18914960a81 /lib/sqlalchemy | |
| parent | a3473c08d35e2cce32b014519df5f774c0166cf1 (diff) | |
| download | sqlalchemy-4f2d0913fe4fe4f5182f85903a6b3be65ac4fd94.tar.gz | |
Ensure select_from_entity adapter is used in adjust_for_single_inheritance
Fixed issue in single-inheritance loading where the use of an aliased
entity against a single-inheritance subclass in conjunction with the
:meth:`.Query.select_from` method would cause the SQL to be rendered with
the unaliased table mixed in to the query, causing a cartesian product. In
particular this was affecting the new "selectin" loader when used against a
single-inheritance subclass.
Change-Id: Ic2cbe94a5269c101b1f98da9a466180dd4452783
Fixes: #4241
Diffstat (limited to 'lib/sqlalchemy')
| -rw-r--r-- | lib/sqlalchemy/orm/query.py | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py index 54be93055..42f1b2673 100644 --- a/lib/sqlalchemy/orm/query.py +++ b/lib/sqlalchemy/orm/query.py @@ -3542,12 +3542,14 @@ class Query(object): """ search = set(self._mapper_adapter_map.values()) - if self._select_from_entity: - # based on the behavior in _set_select_from, - # when we have self._select_from_entity, we don't - # have _from_obj_alias. - # assert self._from_obj_alias is None - search = search.union([(self._select_from_entity, None)]) + if self._select_from_entity and \ + self._select_from_entity not in self._mapper_adapter_map: + insp = inspect(self._select_from_entity) + if insp.is_aliased_class: + adapter = insp._adapter + else: + adapter = None + search = search.union([(self._select_from_entity, adapter)]) for (ext_info, adapter) in search: if ext_info in self._join_entities: |
