diff options
author | mike bayer <mike_mp@zzzcomputing.com> | 2020-07-07 18:58:18 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@bbpush.zzzcomputing.com> | 2020-07-07 18:58:18 +0000 |
commit | a6d8b674e92ef1cabdb2ab85490397f3ed12a42c (patch) | |
tree | da1bc2912b3465939bee40a5f649053977ca85c7 /lib | |
parent | bcb2421e9faaab8ce48e2731b9a2f7411204f393 (diff) | |
parent | 6eea9ca437084feae6a7b00276547e70ef6b40ad (diff) | |
download | sqlalchemy-a6d8b674e92ef1cabdb2ab85490397f3ed12a42c.tar.gz |
Merge "ensure we unwrap desc() /label() all the way w/ order by"
Diffstat (limited to 'lib')
-rw-r--r-- | lib/sqlalchemy/sql/util.py | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/lib/sqlalchemy/sql/util.py b/lib/sqlalchemy/sql/util.py index e8726000b..b803ef912 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 Label from .elements import Null from .elements import UnaryExpression from .schema import Column @@ -279,14 +280,31 @@ def unwrap_order_by(clause): cols = util.column_set() result = [] stack = deque([clause]) + + # examples + # column -> ASC/DESC == column + # column -> ASC/DESC -> label == column + # column -> label -> ASC/DESC -> label == column + # scalar_select -> label -> ASC/DESC == scalar_select -> label + while stack: t = stack.popleft() if isinstance(t, ColumnElement) and ( not isinstance(t, UnaryExpression) or not operators.is_ordering_modifier(t.modifier) ): - if isinstance(t, _label_reference): + if isinstance(t, Label) and not isinstance( + t.element, ScalarSelect + ): + t = t.element + + stack.append(t) + continue + elif isinstance(t, _label_reference): t = t.element + + stack.append(t) + continue if isinstance(t, (_textual_label_reference)): continue if t not in cols: |