summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql
diff options
context:
space:
mode:
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):