#26305: Can't filter ChangeList by postgres-specific lookups
-------------------------------+--------------------
     Reporter:  tsouvarev      |      Owner:  nobody
         Type:  Uncategorized  |     Status:  new
    Component:  contrib.admin  |    Version:  1.9
     Severity:  Normal         |   Keywords:
 Triage Stage:  Unreviewed     |  Has patch:  0
Easy pickings:  0              |      UI/UX:  0
-------------------------------+--------------------
 Say, I have model with ArrayField, and I want to limit choices to
 instances that have length of this array equal to 1:
 {{{
 localhost:8000/admin/app/model/?array_field__len=1
 }}}
 then admin will redirect me to
 {{{
 localhost:8000/admin/app/model/?e=1
 }}}
 Turns out, the following happens:
 - admin try to compose relevant `ChangeList`
 - `ChangeList` in `get_filters` try to determine, should it use `DISTINCT`
 on `array_field`
 - call to `lookup_needs_distinct` happens, which will try to find `len`
 lookup in `QUERY_TERMS` list, and unfortunately `QUERY_TERMS` doesn't have
 any `ArrayField` lookups
 - `len` lookup will be counted as field, but of course, model has no such
 field, so whole thing will fail with `FieldDoesNotExist` exception
 - `FieldDoesNotExist` will be catched and reraised as
 `IncorrectLookupParameters`
 - `IncorrectLookupParameters` will be catched and results in `?e=1`
 redirect

 In Django 1.8 it works fine, because `lookup_needs_distinct` changed later
 in
 
https://github.com/django/django/commit/d084176cc1273d5faf6f88eedb4c490e961f3a68

 Also, I guess that chained lookups like
 `Entry.objects.filter(pub_date__month__gt=6)` won't be working too
 (because `lookup_needs_distinct` looks only on the last token in lookup)

--
Ticket URL: <https://code.djangoproject.com/ticket/26305>
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/052.fa83cc4e22a9f3af517806f3bd30ca52%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to