diff --git a/netbox/core/api/schema.py b/netbox/core/api/schema.py index fad907ac1..a8feffc60 100644 --- a/netbox/core/api/schema.py +++ b/netbox/core/api/schema.py @@ -158,6 +158,11 @@ class NetBoxAutoSchema(AutoSchema): fields = {} if hasattr(serializer, 'child') else serializer.fields remove_fields = [] + """ + If you get a failure here for: AttributeError: 'cached_property' object has no attribute 'items' + it is probably because you are using a viewsets.ViewSet for the API View and are defining a + serializer_class. You will also need to define a get_serializer function like GenericAPIView. + """ for child_name, child in fields.items(): # read_only fields don't need to be in writable (write only) serializers if 'read_only' in dir(child) and child.read_only: diff --git a/netbox/core/api/views.py b/netbox/core/api/views.py index f25023bec..4e5b148fc 100644 --- a/netbox/core/api/views.py +++ b/netbox/core/api/views.py @@ -104,6 +104,15 @@ class BaseRQViewSet(viewsets.ViewSet): serializer = self.serializer_class(data, many=True, context={'request': request}) return paginator.get_paginated_response(serializer.data) + def get_serializer(self, *args, **kwargs): + """ + Return the serializer instance that should be used for validating and + deserializing input, and for serializing output. + """ + serializer_class = self.get_serializer_class() + kwargs['context'] = self.get_serializer_context() + return serializer_class(*args, **kwargs) + class BackgroundQueueViewSet(BaseRQViewSet): """