mirror of
https://github.com/django/django.git
synced 2025-06-05 11:39:13 +00:00
[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.
This commit is contained in:
parent
3137174344
commit
af3cfc8630
1
AUTHORS
1
AUTHORS
@ -424,6 +424,7 @@ answer newbie questions, and generally made Django that much better:
|
|||||||
james_027@yahoo.com
|
james_027@yahoo.com
|
||||||
James Aylett
|
James Aylett
|
||||||
James Bennett <james@b-list.org>
|
James Bennett <james@b-list.org>
|
||||||
|
James Gillard <jamesgillard@live.co.uk>
|
||||||
James Murty
|
James Murty
|
||||||
James Tauber <jtauber@jtauber.com>
|
James Tauber <jtauber@jtauber.com>
|
||||||
James Timmins <jameshtimmins@gmail.com>
|
James Timmins <jameshtimmins@gmail.com>
|
||||||
|
@ -265,7 +265,7 @@ class ArrayLenTransform(Transform):
|
|||||||
return (
|
return (
|
||||||
"CASE WHEN %(lhs)s IS NULL THEN NULL ELSE "
|
"CASE WHEN %(lhs)s IS NULL THEN NULL ELSE "
|
||||||
"coalesce(array_length(%(lhs)s, 1), 0) END"
|
"coalesce(array_length(%(lhs)s, 1), 0) END"
|
||||||
) % {"lhs": lhs}, params
|
) % {"lhs": lhs}, params * 2
|
||||||
|
|
||||||
|
|
||||||
@ArrayField.register_lookup
|
@ArrayField.register_lookup
|
||||||
|
@ -9,4 +9,7 @@ Django 4.1.5 fixes several bugs in 4.1.4.
|
|||||||
Bugfixes
|
Bugfixes
|
||||||
========
|
========
|
||||||
|
|
||||||
* ...
|
* Fixed a long standing bug in the ``__len`` lookup for ``ArrayField`` that
|
||||||
|
caused a crash of model validation on
|
||||||
|
:attr:`Meta.constraints <django.db.models.Options.constraints>`
|
||||||
|
(:ticket:`34205`).
|
||||||
|
@ -67,6 +67,16 @@ class SchemaTests(PostgreSQLTestCase):
|
|||||||
RangesModel.objects.create(ints=(20, 50))
|
RangesModel.objects.create(ints=(20, 50))
|
||||||
RangesModel.objects.create(ints=(10, 30))
|
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):
|
def test_check_constraint_daterange_contains(self):
|
||||||
constraint_name = "dates_contains"
|
constraint_name = "dates_contains"
|
||||||
self.assertNotIn(
|
self.assertNotIn(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user