From 1281e6e6c41ad3d7240fe50f4fecab4083b79975 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Thu, 5 Oct 2017 11:25:10 -0400 Subject: Don't include SelectBase when searching for surface column elements Fixed bug where correlated select used against single-table inheritance entity would fail to render correctly in the outer query, due to adjustment for single inheritance discriminator criteria inappropriately re-applying the criteria to the outer query. Change-Id: I38df21f1392af1843e10119682fa0635d346e2a8 Fixes: #4103 --- lib/sqlalchemy/sql/util.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'lib/sqlalchemy/sql') diff --git a/lib/sqlalchemy/sql/util.py b/lib/sqlalchemy/sql/util.py index 281d5f6a3..0c122949b 100644 --- a/lib/sqlalchemy/sql/util.py +++ b/lib/sqlalchemy/sql/util.py @@ -18,7 +18,7 @@ from collections import deque from .elements import BindParameter, ColumnClause, ColumnElement, \ Null, UnaryExpression, literal_column, Label, _label_reference, \ _textual_label_reference -from .selectable import ScalarSelect, Join, FromClause, FromGrouping +from .selectable import SelectBase, ScalarSelect, Join, FromClause, FromGrouping from .schema import Column join_condition = util.langhelpers.public_factory( @@ -235,17 +235,21 @@ def surface_selectables(clause): stack.append(elem.element) -def surface_column_elements(clause): +def surface_column_elements(clause, include_scalar_selects=True): """traverse and yield only outer-exposed column elements, such as would be addressable in the WHERE clause of a SELECT if this element were in the columns clause.""" + filter_ = (FromGrouping, ) + if not include_scalar_selects: + filter_ += (SelectBase, ) + stack = deque([clause]) while stack: elem = stack.popleft() yield elem for sub in elem.get_children(): - if isinstance(sub, FromGrouping): + if isinstance(sub, filter_): continue stack.append(sub) -- cgit v1.2.1