Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#30790 closed Bug (wontfix)

`autocomplete_fields` checks restrict usage to `search_fields` being defined instead of `get_search_fields`

Reported by: Chad G Hansen Owned by: nobody
Component: contrib.admin Version: 2.2
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

It looks like in django.contrib.admin.options (https://github.com/django/django/blob/master/django/contrib/admin/options.py) all references to retrieving search_fields are done through a call to get_search_fields.

However, the checks setup for the autocomplete fields feature only check to see if search_fields is defined and not if get_search_fields returns something.

https://github.com/django/django/blob/master/django/contrib/admin/checks.py#L189

I'm proposing this line:

elif not related_admin.search_fields:

Be changed to also work when get_search_fields returns something:

elif not related_admin.search_fields and not related_admin.get_search_fields(None):

I'm changed this in my local version of Django that I have installed in my project and it works!

Change History (2)

comment:1 by Simon Charette, 5 years ago

Status: newclosed

It feels like this is a case where you'd want to silence the check instead as the system check framework is only meant to perform static analysis, that's the approach we've taken with other admin getter methods in the past.

These methods are also usually overridden to add per-request logic which cannot be captured by passing None and would also backward incompatible.

If your admin class doesn't define request specific logic I suggest you define a search_fields using a @property which will be considered for the check.

comment:2 by Simon Charette, 5 years ago

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