Skip to content
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' object has no attribute 'action' during Schema generation #4398

Closed
mheppner opened this issue Aug 13, 2016 · 1 comment
Closed
Labels
Milestone

Comments

@mheppner
Copy link

Steps to reproduce

Create a ModelViewSet that uses get_serializer_class():

class MyViewSet(viewsets.ModelViewSet):
    queryset = Person.objects.all()

    def get_serializer_class(self):
        if self.action == 'list':
            return serializers.SerializerB
        return serializers.SerializerA

Expected behavior

Schema should be generated in a view that uses the CoreJSONRenderer.

Actual behavior

An AttributeError is thrown: 'MyViewSet' object has no attribute 'action'.

This is related to #4373 and #4278. If this isn't a bug, I may be missing something...the docs do have this method as the suggested way to dynamically change serializers.

Using djangorestframework==3.4.4 and python2.7.

@tomchristie tomchristie added this to the 3.4.5 Release milestone Aug 13, 2016
@tomchristie
Copy link
Member

Yup, makes sense. Thanks for raising this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants