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.py
class TestView(viewsets.ModelViewSet):
@action(methods=['get'], detail=False, url_name='test_action', permission_classes=[IsAuthenticated,])
def test_action(self, request):
return Response()
# urls.py
urlpatterns = [
path('test_urlpattern/', TestViewSet.as_view({'get': 'test_action'},)),
]
# tests.py
@pytest.mark.django_db
def test_case(client):
url = reverse('test_urlpattern')
response = client.get(url)
assert response.status_code == 200 # expected 401!
You can override it using initkwargs
only
# urls.py
urlpatterns = [
# permission will be added
path('test_urlpattern/', TestViewSet.as_view({'get': 'test_action'}, permission_classes=[IsAuthenticated, ])),
]
According to the 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