diff options
author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-01-26 09:31:40 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-26 09:31:40 +0100 |
commit | 2b1242abb3989f5d74e787b09132d01bcbee5b55 (patch) | |
tree | dcef5dace32b0e4946dbfe1dbc18cf027a2d1122 /tests/constraints | |
parent | 882f99031e6e447384bfe22044cc980567d2f40d (diff) | |
download | django-2b1242abb3989f5d74e787b09132d01bcbee5b55.tar.gz |
Fixed #34291 -- Fixed Meta.constraints validation crash on UniqueConstraint with ordered expressions.
Thanks Dan F for the report.
Bug in 667105877e6723c6985399803a364848891513cc.
Diffstat (limited to 'tests/constraints')
-rw-r--r-- | tests/constraints/tests.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/constraints/tests.py b/tests/constraints/tests.py index 5a498f0d73..223b4b3cd5 100644 --- a/tests/constraints/tests.py +++ b/tests/constraints/tests.py @@ -672,6 +672,29 @@ class UniqueConstraintTests(TestCase): exclude={"name"}, ) + def test_validate_ordered_expression(self): + constraint = models.UniqueConstraint( + Lower("name").desc(), name="name_lower_uniq_desc" + ) + msg = "Constraint “name_lower_uniq_desc” is violated." + with self.assertRaisesMessage(ValidationError, msg): + constraint.validate( + UniqueConstraintProduct, + UniqueConstraintProduct(name=self.p1.name.upper()), + ) + constraint.validate( + UniqueConstraintProduct, + UniqueConstraintProduct(name="another-name"), + ) + # Existing instances have their existing row excluded. + constraint.validate(UniqueConstraintProduct, self.p1) + # Unique field is excluded. + constraint.validate( + UniqueConstraintProduct, + UniqueConstraintProduct(name=self.p1.name.upper()), + exclude={"name"}, + ) + def test_validate_expression_condition(self): constraint = models.UniqueConstraint( Lower("name"), |