Opened 6 years ago

Last modified 3 years ago

#22569 assigned Bug

lookup_allowed fails to consider dynamic list_filter

Reported by: Keryn Knight <django@…> Owned by: Simon Meers
Component: contrib.admin Version: master
Severity: Normal Keywords:
Cc: contact@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no


Currently, lookup_allowed iterates over self.list_filter to determine valid params. This is technically incorrect since the introduction of get_list_filter() on ModelAdmin in 1.5, because it is possible to define a ModelAdmin such that self.list_filter is () but get_list_filter yields SimpleListFilter classes.

To correct it, the above code would need to change from:

for filter_item in self.list_filter:


for filter_item in self.get_list_filter(request):

The problem is that now lookup_allowed needs to accept request so that it can pass it back to get_list_filter

In Django itself, that's actually reasonably acceptable as a change, because it's used infrequently - the only place it's actually used is in ChangeList.get_filters, which has access to the request. However, it is overridden in the wild without accept *args, **kwargs, so it'd not be easy to provide a clean upgrade path.

Change History (5)

comment:1 Changed 6 years ago by Tim Graham

Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

comment:3 Changed 5 years ago by ernestoalejo

Cc: contact@… added

comment:4 Changed 3 years ago by Simon Meers

Owner: changed from nobody to Simon Meers
Status: newassigned

comment:6 Changed 3 years ago by Tim Graham

Patch needs improvement: set
Note: See TracTickets for help on using tickets.
Back to Top