Replies: 1 comment 1 reply
-
Filters are called if the field is present in It's not expected though...
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I have a FilterSet with a ModelMultipleChoiceFilter that has a custom method:
After getting some unexpected results, I found out that the custom method is getting called even when the field is not passed as a query param. For example, requests to
/api/book
return an empty list[]
.After digging into it a bit, it seems that every filter gets called regardless if it's passed as a query param. Normally this is fine because they get an empty value and it doesn't apply any filtering. However, when a custom method is supplied, it gets called with
<QuerySet []>
as thevalue
. So in the example above, it filters books by publisher in[]
, which results in the empty result set.I got around it with:
However, I didn't expect the method to get called in the first place, since the request didn't have a "publisher" query param. Am I missing something in the filter configuration that would prevent it from being called in the first place?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions