ChangeList._get_deterministic_ordering() and UniqueConstraint

Hello everyone,

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 was wondering if _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, which was the reason that prompted me to make this post :slight_smile:

What do you think?

Thanks,

Fabio

Yes that sounds like a legitimate improvement to me!

Please follow the contributing guide to open this as a ticket, and work on a PR if you want!
https://docs.djangoproject.com/en/dev/internals/contributing/

Thank you @adamchainz,

I’ll go ahead and file a ticket. I’m willing to work on a PR as well.

EDIT: related ticket at https://code.djangoproject.com/ticket/31187

If anybody’s interested, here is the related PR https://github.com/django/django/pull/12364