3.15 backward compatibility issue with 3.14 - rest_framework.filters.SearchFilter.get_search_terms
returns str
instead of list
#9307
Unanswered
freenoth
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
-
in 3.14 the
get_search_terms
method ofrest_framework.filters.SearchFilter
class was returning a list of termsso we were able to iterate the search terms directly
in 3.15 the same method
get_search_terms
is returning a string representationand to convert the
str
to alist
an additional function was introducedrest_framework.filters.search_smart_split
:and now we have to use this function to iterate the terms explicitly
So the changing of return value type (and the result itself, actually) can break some custom classes, that are using the basic functionality. Moreover it's hard to figure out what is wrong, because both
list
andstr
are iterable, so the implementation works, but with the wrong results.Example:
I had a custom Search filter class based on
rest_framework.filters.SearchFilter
with overridedfilter_queryset
method, so I used the basic method to get the list of search termsand a simple iteration by search terms works well
but after upgrading to 3.15, my iteration started working differently, because now
get_search_terms
is returning a string -> so it works as iteration by string, it's adding every symbol of this string as independent query, instead of one queryfor input
?search=asd
it builds a query like thatinstead of a single search query
so we have to add using a
rest_framework.filters.search_smart_split
function explicitly everywhere to iterate search terms in an old wayis there a chance to use
search_smart_split
inside therest_framework.filters.SearchFilter.get_search_terms
to not to break backward compatibility and method behavior?Beta Was this translation helpful? Give feedback.
All reactions