-
Notifications
You must be signed in to change notification settings - Fork 265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ViewSet.filter_queryset() not being honored, extra parameters #147
Comments
hi @jtsay362 . that was one of the last pieces of legacy code. filters were indeed applied everywhere. now it should only apply to list views and work as expected. fyi and independent of the bug: i also added improved typing support for let me know if that works for you. cheers! |
as far as i am concerned, this issue is resolved. @jtsay362 please inform me if that is not the case and i'll reopen. thx |
@tfranzel I am sorry I did not have a chance to respond. I am fairly new to python, so I had some trouble installing your package from Github. Thank you very much for doing this work. I will for sure give you some feedback when this makes it into the next release. Update: I used 0.9.13 and saw that the non-list endpoints no longer have filter parameters, so this fixed it. Thanks so much! |
hey @jtsay362, no worries. ideally we should confirm fixed before releases 😄 i'm glad though it works for you. for the next issue consider this. that gives you the current master state for testing.
|
Describe the bug
I have these filter backends enabled by default on my DRF settings:
django_filters.rest_framework.DjangoFilterBackend, rest_framework.filters.SearchFilter,
rest_framework.filters.OrderingFilter
But I don't want those applied to non-list views and their presence is adding multiple undesired parameters to the API schema, so I override ViewSet.filter_queryset() to return the argument queryset unchanged if the action is not "list". This seems to disable these filters for non-list views.
However, when I run drf-spectacular, these query parameters remain in the documentation. It does not seem like filter_queryset() is being called during introspection.
To Reproduce
It would be most helpful to provide a small snippet to see how the bug was provoked.
In settings.py:
Add this method to your viewset:
Then run drf-spectacular to generate the schema. "ordering" and "search" are documented as query parameters on the non-list endpoints.
Expected behavior
"ordering" and "search" should not appear as query parameters on the non-list endpoints.
The text was updated successfully, but these errors were encountered: