From: Tobias Petersen Date: Tue, 21 Apr 2026 16:48:17 +0000 (-0400) Subject: Accept OrderByLists in order_by X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=e4e2f94629dd279e5e9dc286b770f9279c36a722;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Accept OrderByLists in order_by Add OrderByRole to acceptable arguments for order_by Fixes: #13248 ### Description Add OrderByRole to acceptable arguments for order_by to solve typing regression ### Checklist This pull request is: - [x] A documentation / typographical / small typing error fix - Good to go, no issue or tests are needed - [x] A short code fix - please include the issue number, and create an issue if none exists, which must include a complete example of the issue. one line code fixes without an issue and demonstration will not be accepted. - Please include: `Fixes: #` in the commit message - please include tests. one line code fixes without tests will not be accepted. - [ ] A new feature implementation - please include the issue number, and create an issue if none exists, which must include a complete example of how the feature would look. - Please include: `Fixes: #` in the commit message - please include tests. **Have a nice day!** Closes: #13251 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/13251 Pull-request-sha: 267e33f31139d4b6c6c3309b5875e1896e10e743 Change-Id: I0778cdecfebfb12bafc5b6027763ae5f5dcf02a2 --- diff --git a/lib/sqlalchemy/sql/selectable.py b/lib/sqlalchemy/sql/selectable.py index 6b10c7fdc7..eb09cfa3a6 100644 --- a/lib/sqlalchemy/sql/selectable.py +++ b/lib/sqlalchemy/sql/selectable.py @@ -4503,9 +4503,12 @@ class GenerativeSelect(DialectKWArgs, SelectBase, Generative): __first: Union[ Literal[None, _NoArg.NO_ARG], _ColumnExpressionOrStrLabelArgument[Any], + roles.OrderByRole, ] = _NoArg.NO_ARG, /, - *clauses: _ColumnExpressionOrStrLabelArgument[Any], + *clauses: Union[ + _ColumnExpressionOrStrLabelArgument[Any], roles.OrderByRole + ], ) -> Self: r"""Return a new selectable with the given list of ORDER BY criteria applied. diff --git a/test/typing/plain_files/sql/common_sql_element.py b/test/typing/plain_files/sql/common_sql_element.py index e4aa2cc5a0..f0b4529f01 100644 --- a/test/typing/plain_files/sql/common_sql_element.py +++ b/test/typing/plain_files/sql/common_sql_element.py @@ -172,6 +172,11 @@ s12730_3 = select(A, B).with_for_update(of=[A, B]) s12730_4 = select(A, B).with_for_update(of=[A, B]) s12730_5 = select(a_table, b_table).with_for_update(of=[a_table, b_table]) +# test 13248 - freestanding asc/desc in order_by +s13248_1 = select(User.id).order_by(asc(User.id)) +s13248_2 = select(User.id).order_by(desc(User.id)) +s13248_3 = select(User.id).order_by(User.id, asc(User.id)) + # with_for_update but for query session = Session()