Opened 11 years ago

Closed 19 months ago

#22569 closed Bug (fixed)

lookup_allowed fails to consider dynamic list_filter

Reported by: Keryn Knight <django@…> Owned by: Sarah Boyce
Component: contrib.admin Version: dev
Severity: Normal Keywords:
Cc: contact@…, Sarah Boyce Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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:

to

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 (12)

comment:1 by Tim Graham, 11 years ago

Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

comment:3 by ernestoalejo, 9 years ago

Cc: contact@… added

comment:4 by Simon Meers, 7 years ago

Owner: changed from nobody to Simon Meers
Status: newassigned

comment:6 by Tim Graham, 7 years ago

Patch needs improvement: set

comment:7 by Mariusz Felisiak, 3 years ago

Owner: Simon Meers removed
Status: assignednew

comment:8 by Mariusz Felisiak, 20 months ago

Cc: Sarah Boyce added

comment:9 by Sarah Boyce, 19 months ago

Owner: set to Sarah Boyce
Patch needs improvement: unset
Status: newassigned

comment:10 by Mariusz Felisiak, 19 months ago

Patch needs improvement: set

comment:11 by Sarah Boyce, 19 months ago

Patch needs improvement: unset

comment:12 by Mariusz Felisiak, 19 months ago

Triage Stage: AcceptedReady for checkin

comment:13 by Mariusz Felisiak <felisiak.mariusz@…>, 19 months ago

Resolution: fixed
Status: assignedclosed

In 594fcc2:

Fixed #22569 -- Made ModelAdmin.lookup_allowed() respect get_list_filter().

Thank you Simon Meers for the initial patch.

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