From 9c0b7baa956a7309f0a95fc36322a759b293eba1 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Thu, 13 Aug 2020 10:43:53 -0400 Subject: Further fixes for ticket 5470 The fix for #5470 didn't actually take into account that the "distinct" logic in query was also doubling up the criteria. Added many more tests. the 1.3 version here will be different than 1.4 as the regression is not quite the same. Fixes: #5470 Change-Id: I16a23917cab175761de9c867d9d9ac55031d9b97 --- lib/sqlalchemy/sql/util.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'lib/sqlalchemy/sql') diff --git a/lib/sqlalchemy/sql/util.py b/lib/sqlalchemy/sql/util.py index 814253266..b3ead718a 100644 --- a/lib/sqlalchemy/sql/util.py +++ b/lib/sqlalchemy/sql/util.py @@ -27,6 +27,7 @@ from .elements import _textual_label_reference from .elements import BindParameter from .elements import ColumnClause from .elements import ColumnElement +from .elements import Grouping from .elements import Label from .elements import Null from .elements import UnaryExpression @@ -298,6 +299,9 @@ def unwrap_order_by(clause): ): t = t.element + if isinstance(t, Grouping): + t = t.element + stack.append(t) continue elif isinstance(t, _label_reference): @@ -310,6 +314,7 @@ def unwrap_order_by(clause): if t not in cols: cols.add(t) result.append(t) + else: for c in t.get_children(): stack.append(c) @@ -338,11 +343,9 @@ def expand_column_list_from_order_by(collist, order_by): ] ) - return [ - col - for col in chain(*[unwrap_order_by(o) for o in order_by]) - if col not in cols_already_present - ] + to_look_for = list(chain(*[unwrap_order_by(o) for o in order_by])) + + return [col for col in to_look_for if col not in cols_already_present] def clause_is_present(clause, search): -- cgit v1.2.1