summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2020-08-13 10:43:53 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2020-08-13 14:26:32 -0400
commit9c0b7baa956a7309f0a95fc36322a759b293eba1 (patch)
tree5284a54db740e02478ff919684b5d6f5ac06a351 /lib/sqlalchemy/sql
parent65da69910944ccbad0c6d008b94ae8271aae4762 (diff)
downloadsqlalchemy-9c0b7baa956a7309f0a95fc36322a759b293eba1.tar.gz
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
Diffstat (limited to 'lib/sqlalchemy/sql')
-rw-r--r--lib/sqlalchemy/sql/util.py13
1 files changed, 8 insertions, 5 deletions
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):