summaryrefslogtreecommitdiff
path: root/tests/constraints
diff options
context:
space:
mode:
authorFrancesco Panico <francesco.panico@fiscozen.it>2023-08-10 14:08:11 +0000
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-08-11 08:51:29 +0200
commit1506f498fe42b65730ece809300c2c0963e38c5a (patch)
tree8c83a06a590e73a4ae88f8cdc43bfa8f1c8f2edc /tests/constraints
parent9946f0b0d9356b55e819f861b31615fa5b548f99 (diff)
Fixed #34743 -- Fixed Meta.constraints validation crash when using pk.
Thanks Nwawel A Iroume for the report.
Diffstat (limited to 'tests/constraints')
-rw-r--r--tests/constraints/tests.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/constraints/tests.py b/tests/constraints/tests.py
index f6571084b0..55397449d9 100644
--- a/tests/constraints/tests.py
+++ b/tests/constraints/tests.py
@@ -352,6 +352,19 @@ class CheckConstraintTests(TestCase):
is_not_null_constraint.validate(JSONFieldModel, JSONFieldModel(data=None))
is_not_null_constraint.validate(JSONFieldModel, JSONFieldModel(data={}))
+ def test_validate_pk_field(self):
+ constraint_with_pk = models.CheckConstraint(
+ check=~models.Q(pk=models.F("age")),
+ name="pk_not_age_check",
+ )
+ constraint_with_pk.validate(ChildModel, ChildModel(pk=1, age=2))
+ msg = f"Constraint “{constraint_with_pk.name}” is violated."
+ with self.assertRaisesMessage(ValidationError, msg):
+ constraint_with_pk.validate(ChildModel, ChildModel(pk=1, age=1))
+ with self.assertRaisesMessage(ValidationError, msg):
+ constraint_with_pk.validate(ChildModel, ChildModel(id=1, age=1))
+ constraint_with_pk.validate(ChildModel, ChildModel(pk=1, age=1), exclude={"pk"})
+
class UniqueConstraintTests(TestCase):
@classmethod