Should SearchFilter.get_schema_operation_parameters return anything if view doesn't declare search_fields? #8944
Unanswered
edi-monefy
asked this question in
Potential Issue
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have the following setup:
As you can see, my viewset doesn't define
search_fields
, even though theSearchFilter
backend is used (in theory, but not in practice). It appears that theSearchFilter
backend returns thesearch
operation param, even though my view doesn't actually use the search feature.I've tracked this down to
rest_framework.filters.SearchFilter.get_schema_operation_parameters
, where it doesn't check if the view has asearch_fields
attribute (and perhaps also check if it's not empty). This doesn't really cause problems in the browsable API, but does add asearch
param to all OpenAPI schema operations (courtesy of drf-spectacular). Needless to say that param is useless, because of no search fields on the view.The question I wanted to bring up is: shouldn't
get_schema_operation_parameters
check whether the view actually declares some search fields and only return the search param in that case? Seems pretty sensible to me, but would like other people's opinion. The workaround (and proposed solution if this turns out to be a good idea) would be something like:Beta Was this translation helpful? Give feedback.
All reactions