#37004 assigned Cleanup/optimization

BaseModelFormSet could leverage totally_ordered property

Reported by: Jacob Walls Owned by: Sarah Boyce
Component: Forms Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

#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:

  • django/forms/models.py

    diff --git a/django/forms/models.py b/django/forms/models.py
    index 104369c0b0..3843203a1d 100644
    a b class BaseModelFormSet(BaseFormSet, AltersData):  
    776776            # If the queryset isn't already ordered we need to add an
    777777            # artificial ordering here to make sure that all formsets
    778778            # constructed from this queryset have the same form order.
    779             if not qs.ordered:
     779            if not qs.totally_ordered:
    780780                qs = qs.order_by(self.model._meta.pk.name)
    781781
    782782            # 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.

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top