Opened 9 years ago

Closed 9 years ago

#26305 closed New feature (duplicate)

Can't filter ChangeList by postgres-specific lookups

Reported by: Ivan Tsouvarev Owned by: nobody
Component: contrib.admin Version: 1.9
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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)

Change History (1)

comment:1 by Tim Graham, 9 years ago

Resolution: duplicate
Status: newclosed
Type: UncategorizedNew feature

Duplicate of #26184

Note: See TracTickets for help on using tickets.
Back to Top