Opened 6 years ago
Closed 6 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 , 6 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:2 by , 6 years ago
| Summary: | ChangeList._get_deterministic_ordering() should inspect UniqueConstraint → Detection of existing total ordering in admin changelist should take into account UniqueConstraints without conditions. |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
| Type: | New feature → Bug |
Agreed, we need to remember to ignore
UniqueConstraint's withcondition's.