Re: [Django] #36880: Postgres hash exclusion constraints are not considered totally unique (was: using hash index as exclusion constraint on USERNAME_FIELD triggers SystemCheckError)

2 views
Skip to first unread message

Django

unread,
Jan 23, 2026, 11:46:13 AM (22 hours ago) Jan 23
to django-...@googlegroups.com
#36880: Postgres hash exclusion constraints are not considered totally unique
-------------------------------------+-------------------------------------
Reporter: Tilman Koschnick | Owner: (none)
Type: Bug | Status: new
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* needs_better_patch: 0 => 1
* stage: Unreviewed => Accepted
* summary:
using hash index as exclusion constraint on USERNAME_FIELD triggers
SystemCheckError
=> Postgres hash exclusion constraints are not considered totally
unique

Comment:

Accepting on the basis that the check logic should be able to consider all
type of unique constraints but the proposed patch is inadequate.

What should be done instead is find a way to have
`django.db.models.options.Options.total_unique_constraints` include such
constraint in a way that doesn't couple `contrib.postgres` with core.

A potential solution could be to introduce a
`Constraint.totally_unique_for_fields -> set[tuple[str]] | None` method
which is implemented by `UniqueConstraint` and `ExclusionConstraint`.
--
Ticket URL: <https://code.djangoproject.com/ticket/36880#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Reply all
Reply to author
Forward
0 new messages