#34166: UniqueConstraint with condition not validated if the condition field is
not
editable
-------------------------------------+-------------------------------------
Reporter: Márton | Owner: nobody
Salomváry |
Type: Bug | Status: new
Component: Database | Version: 4.1
layer (models, ORM) | Keywords: model validation
Severity: Normal | unique constraint condition
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Given a model with a UniqueConstraint that has a condition with a field
that is not editable
when I try to save this model with an (admin) form with an invalid value
for the UniqueConstraint
I expect to get a (Django) validation error.
What I get instead is a database-level integrity error.
If the condition field is editable, I do get a validation error (although
a form level one, not a field level one, which might be another bug).
If there is no condition on the field, I do get the expected field level
validation error.
Example:
{{{
class Thing(models.Model):
name = models.CharField(max_length=10)
status = models.CharField(max_length=10, blank=True, editable=False)
class Meta:
constraints = [
models.UniqueConstraint(
fields=["name"],
name="thing_unique_name",
condition=~Q(status="archived"),
)
]
}}}
Small test case repo:
https://github.com/salomvary/django_partial_constraint_bug
(To reproduce, go to http://127.0.0.1:8000/admin/thing/thing/add/ and try
to add two Things with the same name.)
I've tried the latest dev version of Django, which has same problem.
--
Ticket URL: <https://code.djangoproject.com/ticket/34166>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/0107018481544240-3097252b-b2c5-4259-adcd-48f3ea2c46e3-000000%40eu-central-1.amazonses.com.