Fixed #35275 -- Fixed Meta.constraints validation crash on UniqueConstraint with OpClass().

This also introduces Expression.constraint_validation_compatible that
allows specifying that expression should be ignored during a constraint
validation.
This commit is contained in:
Mariusz Felisiak 2024-05-12 20:10:55 +02:00 committed by Sarah Boyce
parent ceaf1e2848
commit f030236a86
8 changed files with 61 additions and 11 deletions

View file

@ -266,6 +266,19 @@ class SchemaTests(PostgreSQLTestCase):
self.assertNotIn(constraint.name, self.get_constraints(Scene._meta.db_table))
Scene.objects.create(scene="ScEnE 10", setting="Sir Bedemir's Castle")
def test_opclass_func_validate_constraints(self):
constraint_name = "test_opclass_func_validate_constraints"
constraint = UniqueConstraint(
OpClass(Lower("scene"), name="text_pattern_ops"),
name="test_opclass_func_validate_constraints",
)
Scene.objects.create(scene="First scene")
# Non-unique scene.
msg = f"Constraint “{constraint_name}” is violated."
with self.assertRaisesMessage(ValidationError, msg):
constraint.validate(Scene, Scene(scene="first Scene"))
constraint.validate(Scene, Scene(scene="second Scene"))
class ExclusionConstraintTests(PostgreSQLTestCase):
def get_constraints(self, table):