diff options
| author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2024-05-12 20:10:55 +0200 |
|---|---|---|
| committer | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2024-05-14 10:34:30 +0200 |
| commit | f030236a86a64a4befd3cc8093e2bbeceef52a31 (patch) | |
| tree | 170718dd1a0685ee154ea7f6e3a52cae998a6062 /tests/postgres_tests/test_constraints.py | |
| parent | ceaf1e2848583ba832cc74715da38c802b6b0671 (diff) | |
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.
Diffstat (limited to 'tests/postgres_tests/test_constraints.py')
| -rw-r--r-- | tests/postgres_tests/test_constraints.py | 13 |
1 files changed, 13 insertions, 0 deletions
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): |
