From f030236a86a64a4befd3cc8093e2bbeceef52a31 Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Sun, 12 May 2024 20:10:55 +0200 Subject: 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. --- tests/postgres_tests/test_constraints.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'tests/postgres_tests/test_constraints.py') diff --git a/tests/postgres_tests/test_constraints.py b/tests/postgres_tests/test_constraints.py index b3de53efd7..3cc76cdcfe 100644 --- a/tests/postgres_tests/test_constraints.py +++ b/tests/postgres_tests/test_constraints.py @@ -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): -- cgit v1.3