Fix ad-hoc filter support for Django 5 #55
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Ad-hoc filters (ie, those not declared in
list_filter) is broken when using Django 5+.Such filtering is supported when using Django 4x (also, it's supported by current Django 5+ ModelAdmin).
The issue is that we are passing around a
QueryDictof query params inIndexView, and in some places calling.items()on it, which has a flattening affect on values.This means that, for an undeclared query param:
get_filtersmethod returns only the last value for a multi-value query, andget_querysetpasses adict[str, str]tobuild_q_object_from_lookup_parametersDjango util, which treats the value part of.items()as a list.The latter means that a string value gets treated as a list that is OR'd:
E.g. given a query param:
location=Hobart, we get a queryset withWHERE location='H' OR location='o' OR location='b'...The tests that accompanied support for multi-valued query params did not capture this because the filter being tested is declared in
list_filter. wagtail/wagtail#10242