[Django] #37255: Tests rely on unspecified row order of SELECT without ORDER BY

10 views
Skip to first unread message

Django

unread,
Aug 7, 2026, 8:50:59 AMAug 7
to django-...@googlegroups.com
#37255: Tests rely on unspecified row order of SELECT without ORDER BY
---------------------------------------------+----------------------------
Reporter: Yaroslav K | Owner: Yaroslav K
Type: Uncategorized | Status: assigned
Component: Testing framework | Version: dev
Severity: Normal | Keywords: test
Triage Stage: Unreviewed | Has patch: 1
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
---------------------------------------------+----------------------------
Many (~70) tests assert a specific row order for querysets whose SQL has
no
`ORDER BY`. SQL standard does not define that order.

On PostgreSQL the rows usually arrive in physical storage order, which
on a freshly loaded table matches insertion order -- so these assertions
pass by coincidence rather than by contract. That breaks when rows are
updated or deleted and the space is reused, or when the planner picks a
different access path such as an index scan. A test like this can start
failing with no change to Django or to the test itself.

Proposed solution:

1. add `order_by()` where the asserted sequence is meaningful
2. use `assertCountEqual()` otherwise

Found by running the suite under
[https://github.com/viralpraxis/pg_disorder pg_disorder].
--
Ticket URL: <https://code.djangoproject.com/ticket/37255>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Aug 7, 2026, 3:23:06 PMAug 7
to django-...@googlegroups.com
#37255: Tests rely on unspecified row order of SELECT without ORDER BY
------------------------------+--------------------------------------
Reporter: Yaroslav K | Owner: Yaroslav K
Type: Bug | Status: assigned
Component: Core (Other) | Version: dev
Severity: Normal | Resolution:
Keywords: test | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------
Changes (by Tim Graham):

* component: Testing framework => Core (Other)
* stage: Unreviewed => Accepted
* type: Uncategorized => Bug

--
Ticket URL: <https://code.djangoproject.com/ticket/37255#comment:1>

Django

unread,
Aug 21, 2026, 12:02:56 PM (2 days ago) Aug 21
to django-...@googlegroups.com
#37255: Tests rely on unspecified row order of SELECT without ORDER BY
------------------------------+--------------------------------------
Reporter: Yaroslav K | Owner: Yaroslav K
Type: Bug | Status: assigned
Component: Core (Other) | Version: dev
Severity: Normal | Resolution:
Keywords: test | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------
Changes (by Jacob Walls):

* needs_better_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/37255#comment:2>

Django

unread,
Aug 22, 2026, 10:03:05 AM (yesterday) Aug 22
to django-...@googlegroups.com
#37255: Tests rely on unspecified row order of SELECT without ORDER BY
-------------------------------------+-------------------------------------
Reporter: Yaroslav K | Owner: Yaroslav
| K
Type: Bug | Status: assigned
Component: Core (Other) | Version: dev
Severity: Normal | Resolution:
Keywords: test | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls):

* needs_better_patch: 1 => 0
* stage: Accepted => Ready for checkin

--
Ticket URL: <https://code.djangoproject.com/ticket/37255#comment:3>
Reply all
Reply to author
Forward
0 new messages