diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-04-02 22:12:09 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-04-02 23:42:36 -0400 |
| commit | 25a42e93f4ef5ce1a9f9c23fbcdea3e21a7b3f1a (patch) | |
| tree | eeac2f3da63270443bffbb59d8001a1a309b3344 /lib/sqlalchemy/sql | |
| parent | fd2ecb5f87c1c0132263b5a35067c4bb76160fb2 (diff) | |
| download | sqlalchemy-25a42e93f4ef5ce1a9f9c23fbcdea3e21a7b3f1a.tar.gz | |
Fold entities into existing joins when resolving FROM ambiguity
Fixed 1.3 regression in new "ambiguous FROMs" query logic introduced in
:ref:`change_4365` where a :class:`.Query` that explicitly places an entity
in the FROM clause with :meth:`.Query.select_from` and also joins to it
using :meth:`.Query.join` would later cause an "ambiguous FROM" error if
that entity were used in additional joins, as the entity appears twice in
the "from" list of the :class:`.Query`. The fix resolves this ambiguity by
folding the standalone entity into the join that it's already a part of in
the same way that ultimately happens when the SELECT statement is rendered.
Fixes: #4584
Change-Id: Ic62ca09c6d329695b21ed4f1be8621edcbb18e19
Diffstat (limited to 'lib/sqlalchemy/sql')
| -rw-r--r-- | lib/sqlalchemy/sql/util.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/sqlalchemy/sql/util.py b/lib/sqlalchemy/sql/util.py index 3077840c6..8719b26ec 100644 --- a/lib/sqlalchemy/sql/util.py +++ b/lib/sqlalchemy/sql/util.py @@ -20,6 +20,7 @@ from .annotation import _shallow_annotate # noqa from .base import _from_objects from .base import ColumnSet from .ddl import sort_tables # noqa +from .elements import _expand_cloned from .elements import _find_columns # noqa from .elements import _label_reference from .elements import _textual_label_reference @@ -149,6 +150,16 @@ def find_left_clause_to_join_from(clauses, join_to, onclause): idx.append(i) break + if len(idx) > 1: + # this is the same "hide froms" logic from + # Selectable._get_display_froms + toremove = set( + chain(*[_expand_cloned(f._hide_froms) for f in clauses]) + ) + idx = [ + i for i in idx if clauses[i] not in toremove + ] + # onclause was given and none of them resolved, so assume # all indexes can match if not idx and onclause is not None: |
