summaryrefslogtreecommitdiff
path: root/tests/postgres_tests
diff options
context:
space:
mode:
authorJames Gillard <jamesgillard@live.co.uk>2022-12-10 15:46:23 +0000
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-12-10 19:39:00 +0100
commitaf3cfc863095e70f752c6b1875ed5c5dbaac2c4a (patch)
treee7729c75470578ef90fe236c944811056b7c3c24 /tests/postgres_tests
parent3137174344775fa2358e39cd90e6137f292f8daa (diff)
[4.1.x] Fixed #34205 -- Fixed Meta.constraints validation crash with ArrayField and __len lookup.
Regression in 88fc9e2826044110b7b22577a227f122fe9c1fb5 that began manifesting in Django 4.1. Backport of c5ed884eabf3b2b67581c55bf6c87e721f69157f from main.
Diffstat (limited to 'tests/postgres_tests')
-rw-r--r--tests/postgres_tests/test_constraints.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/tests/postgres_tests/test_constraints.py b/tests/postgres_tests/test_constraints.py
index 74c07e4fab..a45aed153d 100644
--- a/tests/postgres_tests/test_constraints.py
+++ b/tests/postgres_tests/test_constraints.py
@@ -67,6 +67,16 @@ class SchemaTests(PostgreSQLTestCase):
RangesModel.objects.create(ints=(20, 50))
RangesModel.objects.create(ints=(10, 30))
+ def test_check_constraint_array_length(self):
+ constraint = CheckConstraint(
+ check=Q(field__len=1),
+ name="array_length",
+ )
+ msg = f"Constraint “{constraint.name}” is violated."
+ with self.assertRaisesMessage(ValidationError, msg):
+ constraint.validate(IntegerArrayModel, IntegerArrayModel())
+ constraint.validate(IntegerArrayModel, IntegerArrayModel(field=[1]))
+
def test_check_constraint_daterange_contains(self):
constraint_name = "dates_contains"
self.assertNotIn(