Opened 4 years ago

Closed 4 years ago

#31187 closed Bug (fixed)

Detection of existing total ordering in admin changelist should take into account UniqueConstraints without conditions.

Reported by: Fabio Sangiovanni Owned by: Fabio Sangiovanni
Component: contrib.admin Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I've been fiddling with db indexes lately to improve the performance of an admin view.
Eventually I found this PR https://github.com/django/django/pull/10692 which ensures the records displayed by ChangeList are deterministically ordered.
Among other things, the code looks for the presence of a unique_together attribute on the Meta class of the model to determine if the model is already totally ordered.

I think that _get_deterministic_ordering() should check for the presence of UniqueConstraints as well, which currently aren’t considered by the discovery algorithm.

I noticed the docs currently advise against using unique_together in favor of UniqueConstraint, suggesting the former may be deprecated in the future, so this fix would change that part of the code accordingly.

I'm willing to submit a PR for this.

Cheers,
Fabio

Change History (5)

comment:1 by Fabio Sangiovanni, 4 years ago

Owner: changed from nobody to Fabio Sangiovanni
Status: newassigned

comment:2 by Mariusz Felisiak, 4 years ago

Summary: ChangeList._get_deterministic_ordering() should inspect UniqueConstraintDetection of existing total ordering in admin changelist should take into account UniqueConstraints without conditions.
Triage Stage: UnreviewedAccepted
Type: New featureBug

Agreed, we need to remember to ignore UniqueConstraint's with condition's.

comment:3 by Fabio Sangiovanni, 4 years ago

Has patch: set

comment:4 by Mariusz Felisiak <felisiak.mariusz@…>, 4 years ago

In d270c10a:

Refs #31187 -- Added total_unique_constraints property to model's Options.

comment:5 by Mariusz Felisiak <felisiak.mariusz@…>, 4 years ago

Resolution: fixed
Status: assignedclosed

In b457068c:

Fixed #31187 -- Fixed detecting of existing total ordering in admin changelist when using Meta.constraints.

Detection of existing total ordering in admin changelist now takes into
account non-partial unique constraints.

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