[4.1.x] Fixed #34205 -- Fixed Meta.constraints validation crash with ArrayField and __len lookup.

Regression in 88fc9e2826 that began
manifesting in Django 4.1.

Backport of c5ed884eab from main.
This commit is contained in:
James Gillard 2022-12-10 15:46:23 +00:00 committed by Mariusz Felisiak
parent 3137174344
commit af3cfc8630
4 changed files with 16 additions and 2 deletions

View file

@ -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(