[Django] #37004: BaseModelFormSet could leverage totally_ordered property

1 view
Skip to first unread message

Django

unread,
Mar 24, 2026, 4:36:40 PM (2 days ago) Mar 24
to django-...@googlegroups.com
#37004: BaseModelFormSet could leverage totally_ordered property
-------------------------------------+-------------------------------------
Reporter: Jacob | Owner: Sarah Boyce
Walls |
Type: | Status: assigned
Cleanup/optimization |
Component: Forms | Version: dev
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
#36857 added a new property `totally_ordered` on `QuerySet` to capture the
difference between a queryset having ''some'' ordering versus a "stable,
deterministic" ordering.

I noticed that we probably want to use that new property here in
`BaseModelFormSet` for the purpose described in #10163:

{{{#!diff
diff --git a/django/forms/models.py b/django/forms/models.py
index 104369c0b0..3843203a1d 100644
--- a/django/forms/models.py
+++ b/django/forms/models.py
@@ -776,7 +776,7 @@ class BaseModelFormSet(BaseFormSet, AltersData):
# If the queryset isn't already ordered we need to add an
# artificial ordering here to make sure that all formsets
# constructed from this queryset have the same form order.
- if not qs.ordered:
+ if not qs.totally_ordered:
qs = qs.order_by(self.model._meta.pk.name)

# Removed queryset limiting here. As per discussion re:
#13023
}}}

Tentatively assigning to Sarah to see if a good fit for any Djangonauts
this session. This would involve cooking up a test.
--
Ticket URL: <https://code.djangoproject.com/ticket/37004>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Reply all
Reply to author
Forward
0 new messages