Custom GET "action" endpoint not displaying query params
See original GitHub issueDescribe the bug Query params don’t show up in an “@action” that doesn’t take a list serializer class.
I understand the point of view here of query params being for listing resources, but I’d like to know if there’s any way to bypass this check to load the query params anyway.
To Reproduce
This won’t display query params.
class UserViewSet(GenericViewSet, ListModelMixin):
filterset_class = FilterSetClass
@action(
detail=False,
methods=["GET"],
# Using this serializer solely to display correct output
serializer_class=NonListSerializer,
)
def export_csv(...):
# Use query params to setup an async job
return Response({"job_id": <uuid>})
Expected behavior Should display query params correctly.
After a quick look at the code, seems like if if is_list_serializer(serializer)
and if hasattr(self.view, 'action')
happen after if isinstance(self.view, ListModelMixin)
at drf_spectacular.openapi.AutoSchema._is_list_view
, then it’d render the query params alright.
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Query string not working while using attribute routing
Query strings are behaving the same way as before. Update 2 I now have a singular action in my controller: [RoutePrefix("1/Names")] public ...
Read more >Tutorial: Build a REST API with HTTP non-proxy integration
Learn how to create an API Gateway API with the HTTP custom integration using the ... The preceding endpoint can take two query...
Read more >URLSearchParams - Web APIs - MDN Web Docs
Chrome Edge
URLSearchParams Full support. Chrome49. Toggle history Full support. Edge...
@@iterator Full support. Chrome49. Toggle history Full support. Edge...
URLSearchParams() constructor Full support. Chrome49. Toggle...
Read more >ASP.NET Core Blazor routing and navigation - Microsoft Learn
Learn how to manage request routing in Blazor apps and how to use the Navigation Manager and NavLink component for navigation.
Read more >Routers - Django REST framework
Typically you won't need to specify the basename argument, but if you have a viewset where you've defined a custom get_queryset method, then...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for the clarification, @tfranzel! I finally managed to get it working. I actually made a mistake in that PR I sent. Here’s the snipper for historical purpose:
https://github.com/tfranzel/drf-spectacular/blob/deb83250f078ed4bce17b12972e098409ac69ec9/drf_spectacular/openapi.py#L367
is where you would insert something that bypasses
self._is_list_view()
for your specific filterset class. i would not touchis_list_view
itself but rather bypass thatreturn []
only in your specific case emerges.