summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2023-01-26 09:31:40 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-01-26 09:32:14 +0100
commit719a14badcd226732c9c1172f8183e5f42e54241 (patch)
treed37037b202d382663d1fea68a57f2393dfbd8499 /tests
parentd43fbdf6f11d2a1592bc5c6d7c3fdbcd617e35f6 (diff)
[4.2.x] Fixed #34291 -- Fixed Meta.constraints validation crash on UniqueConstraint with ordered expressions.
Thanks Dan F for the report. Bug in 667105877e6723c6985399803a364848891513cc. Backport of 2b1242abb3989f5d74e787b09132d01bcbee5b55 from main
Diffstat (limited to 'tests')
-rw-r--r--tests/constraints/tests.py23
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"),