Re: [Django] #34205: Validation of constraints with __len lookup crashes for ArrayFields. (was: Arrayfield constraint validation crash in 4.1)

2 views
Skip to first unread message

Django

unread,
Dec 9, 2022, 5:47:54 AM12/9/22
to django-...@googlegroups.com
#34205: Validation of constraints with __len lookup crashes for ArrayFields.
-------------------------------------+-------------------------------------
Reporter: James Gillard | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 4.1
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* type: Uncategorized => Bug
* severity: Normal => Release blocker
* stage: Unreviewed => Accepted


Comment:

Thanks for the report! It is a long standing bug introduced in
88fc9e2826044110b7b22577a227f122fe9c1fb5 that began manifesting in Django
4.1. The following patch fixes it for me:
{{{#!diff
diff --git a/django/contrib/postgres/fields/array.py
b/django/contrib/postgres/fields/array.py
index c247387eb7..eaff032465 100644
--- a/django/contrib/postgres/fields/array.py
+++ b/django/contrib/postgres/fields/array.py
@@ -297,7 +297,7 @@ class ArrayLenTransform(Transform):
return (
"CASE WHEN %(lhs)s IS NULL THEN NULL ELSE "
"coalesce(array_length(%(lhs)s, 1), 0) END"
- ) % {"lhs": lhs}, params
+ ) % {"lhs": lhs}, params * 2


@ArrayField.register_lookup
}}}
We two `lhs`, so we need to pass `params` for both.

Would you like to prepare a patch? (a regression test is required, I'd add
it to the `postgres_tests.test_constraints.SchemaTests`.)

--
Ticket URL: <https://code.djangoproject.com/ticket/34205#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Reply all
Reply to author
Forward
0 new messages