]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Accept OrderByLists in order_by
authorTobias Petersen <tobias.petersen@mikrodust.com>
Tue, 21 Apr 2026 16:48:17 +0000 (12:48 -0400)
committersqla-tester <sqla-tester@sqlalchemy.org>
Tue, 21 Apr 2026 16:48:17 +0000 (12:48 -0400)
Add OrderByRole to acceptable arguments for order_by

Fixes: #13248
### Description
Add OrderByRole to acceptable arguments for order_by to solve typing regression

### Checklist
<!-- go over following points. check them with an `x` if they do apply, (they turn into clickable checkboxes once the PR is submitted, so no need to do everything at once)

-->

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: #<issue number>` 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: #<issue number>` 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

lib/sqlalchemy/sql/selectable.py
test/typing/plain_files/sql/common_sql_element.py

index 6b10c7fdc720d28ae861533d1f1829b448f98b29..eb09cfa3a667c4bf0d40da219e53176ec63f6b71 100644 (file)
@@ -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.
index e4aa2cc5a06234e152b854c561668f0f270f8c8b..f0b4529f01bd62dd104897aa8bc5f025a639eee9 100644 (file)
@@ -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()