﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
34166	UniqueConstraint with condition not validated if the condition field is not editable.	Márton Salomváry	nobody	"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.
"	New feature	closed	Database layer (models, ORM)	4.1	Normal	wontfix	model validation unique constraint condition		Unreviewed	0	0	0	0	0	0
