]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Explicitly state what happens if `order_by` is called more than once. (#8791)
authorEitan Mosenkis <eitan@mosenkis.net>
Mon, 14 Nov 2022 21:11:15 +0000 (23:11 +0200)
committerFederico Caselli <cfederico87@gmail.com>
Mon, 14 Nov 2022 21:12:43 +0000 (22:12 +0100)
* Explicitly state what happens if `order_by` is called more than once.

The existing docs cover how to clear existing `order_by` clauses but don't actually describe the behavior of calling `order_by` multiple times with different clauses.

* Also update Select.order_by.

(cherry picked from commit 9237bf15e612ba82555444751bd69dc2a831e7f4)

lib/sqlalchemy/orm/query.py
lib/sqlalchemy/sql/selectable.py

index 65b6bf81a04cd96f89510ced5f550352b666d255..cef98201f3d305f8e601ef90da676ec5cac76527 100644 (file)
@@ -1819,9 +1819,10 @@ class Query(
 
             q = session.query(Entity).order_by(Entity.id, Entity.name)
 
-        All existing ORDER BY criteria may be cancelled by passing
-        ``None`` by itself.  New ORDER BY criteria may then be added by
-        invoking :meth:`_orm.Query.order_by` again, e.g.::
+        Calling this method multiple times is equivalent to calling it once
+        with all the clauses concatenated. All existing ORDER BY criteria may
+        be cancelled by passing ``None`` by itself.  New ORDER BY criteria may
+        then be added by invoking :meth:`_orm.Query.order_by` again, e.g.::
 
             # will erase all ORDER BY and ORDER BY new_col alone
             q = q.order_by(None).order_by(new_col)
index 956f8ae8d8adc018096f6a6d49dcde05d130d3a9..f8252cbe468965752aa7d4b0c9185c80fac26c8e 100644 (file)
@@ -3876,9 +3876,10 @@ class GenerativeSelect(DeprecatedSelectBaseGenerations, SelectBase):
 
             stmt = select(table).order_by(table.c.id, table.c.name)
 
-        All existing ORDER BY criteria may be cancelled by passing
-        ``None`` by itself.  New ORDER BY criteria may then be added by
-        invoking :meth:`_sql.Select.order_by` again, e.g.::
+        Calling this method multiple times is equivalent to calling it once
+        with all the clauses concatenated. All existing ORDER BY criteria may
+        be cancelled by passing ``None`` by itself.  New ORDER BY criteria may
+        then be added by invoking :meth:`_orm.Query.order_by` again, e.g.::
 
             # will erase all ORDER BY and ORDER BY new_col alone
             stmt = stmt.order_by(None).order_by(new_col)