diff options
| author | Jacob Walls <jacobtylerwalls@gmail.com> | 2026-02-09 15:09:56 -0500 |
|---|---|---|
| committer | Jacob Walls <jacobtylerwalls@gmail.com> | 2026-02-09 16:19:13 -0500 |
| commit | 7cf1c22d4dfdd46f2082cfc55b714b68c4fd2de3 (patch) | |
| tree | 69132e550eac9916fe5dcc02db29dd9bc0b4b8a4 /docs/ref | |
| parent | 0deedbd55713d3aa1da9f88063705168bf7a4e9c (diff) | |
Refs #36644 -- Documented no pk ordering in first()/last() after empty order_by().
Diffstat (limited to 'docs/ref')
| -rw-r--r-- | docs/ref/models/querysets.txt | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/docs/ref/models/querysets.txt b/docs/ref/models/querysets.txt index 890395f6de..c819015b25 100644 --- a/docs/ref/models/querysets.txt +++ b/docs/ref/models/querysets.txt @@ -2774,8 +2774,9 @@ the direction is changed. *Asynchronous version*: ``afirst()`` Returns the first object matched by the queryset, or ``None`` if there -is no matching object. If the ``QuerySet`` has no ordering defined, then the -queryset is automatically ordered by the primary key. This can affect +is no matching object. If the ``QuerySet`` has no ordering defined (and has not +had ordering forcibly cleared by calling :meth:`order_by` with no arguments), +then the queryset is automatically ordered by the primary key. This can affect aggregation results as described in :ref:`aggregation-ordering-interaction`. Example:: @@ -2790,6 +2791,12 @@ equivalent to the above example:: except IndexError: p = None +.. versionchanged:: 6.1 + + ``first()`` and :meth:`last` no longer order by the primary key when + ordering has been forcibly cleared by calling :meth:`order_by` with no + arguments. + ``last()`` ~~~~~~~~~~ |
