Skip to content

'ViewSet' object has no attribute 'action' during Schema generation #4398

@mheppner

Description

@mheppner

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy