#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.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/01070184f67fa4a2-23076a04-4e16-414a-a79c-451094b7540a-000000%40eu-central-1.amazonses.com.

Reply via email to