Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7k
Open
Description
Hi,
I encountered a problem when overriding viewset-level attributes doesn't work for actions if a route is configured as.as_view()
.
Example:
# views.pyclassTestView(viewsets.ModelViewSet):@action(methods=['get'],detail=False,url_name='test_action',permission_classes=[IsAuthenticated,])deftest_action(self,request):returnResponse()# urls.pyurlpatterns= [path('test_urlpattern/',TestViewSet.as_view({'get':'test_action'},)),]# tests.py@pytest.mark.django_dbdeftest_case(client):url=reverse('test_urlpattern')response=client.get(url)assertresponse.status_code==200# expected 401!
You can override it usinginitkwargs
only
# urls.pyurlpatterns= [# permission will be addedpath('test_urlpattern/',TestViewSet.as_view({'get':'test_action'},permission_classes=[IsAuthenticated, ])),]
According tothe docs, it's not clear this feature works for Router configuration only. No exceptions, warnings, or even related github issues were found regarding this.

Metadata
Metadata
Assignees
Labels
No labels