Fixed #34205 -- Fixed Meta.constraints validation crash with ArrayField and __len lookup.

Regression in 88fc9e2826 that began
manifesting in Django 4.1.
This commit is contained in:
James Gillard 2022-12-10 15:46:23 +00:00 committed by Mariusz Felisiak
parent b8738aea14
commit c5ed884eab
4 changed files with 16 additions and 2 deletions

View file

@ -76,6 +76,16 @@ class SchemaTests(PostgreSQLTestCase):
constraint.validate(IntegerArrayModel, IntegerArrayModel())
constraint.validate(IntegerArrayModel, IntegerArrayModel(field=[1]))
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(