#25772: ArrayField: incorrent len lookup on empty arrays
----------------------------------+------------------------------------
     Reporter:  mrAdm             |                    Owner:
         Type:  Bug               |                   Status:  new
    Component:  contrib.postgres  |                  Version:  1.8
     Severity:  Normal            |               Resolution:
     Keywords:                    |             Triage Stage:  Accepted
    Has patch:  1                 |      Needs documentation:  0
  Needs tests:  0                 |  Patch needs improvement:  0
Easy pickings:  0                 |                    UI/UX:  0
----------------------------------+------------------------------------
Changes (by Uran198):

 * has_patch:  0 => 1


Comment:

 In case field is None coalesce will return 0. So,
 {{{
 SELECT * FROM ... WHERE COALESCE(array_length("field", 1), 0)=0
 }}}
 will also return entries with field==None.
 The solution is probably to change line in
 
https://github.com/django/django/blob/master/django/contrib/postgres/fields/array.py#L205
 to
 {{{#!python
         return '%s IS NOT NULL AND \
                 coalesce(array_length(%s, 1), 0)' % (lhs, lhs), params
 }}}
 or
 {{{#!python
         return 'CASE WHEN %s IS NULL THEN NULL \
                 ELSE coalesce(array_length(%s, 1), 0) \
                 END' % (lhs, lhs), params
 }}}
 [https://github.com/django/django/pull/5705 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/25772#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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/063.3041ea92267b81c8fd70a4ebbdb1b38a%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to