From af3cfc863095e70f752c6b1875ed5c5dbaac2c4a Mon Sep 17 00:00:00 2001 From: James Gillard Date: Sat, 10 Dec 2022 15:46:23 +0000 Subject: [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. --- tests/postgres_tests/test_constraints.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tests/postgres_tests') 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( -- cgit v1.3