-
Notifications
You must be signed in to change notification settings - Fork 271
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
AttributeError: 'ListSerializer' object has no attribute 'fields' #29
Comments
Hi @srtab, thats for raising that issue. spectacular should never bail with an exception so this is a bug. actually ListSerializers are usually auto-substituted by using could you please provide a small snipped on how you use |
I'm using it to make bulk updates, here is an simple example:
from rest_framework import serializers
from .models import Step
class StepSerializer(serializers.ModelSerializer):
class Meta:
model = Step
fields = ("pk", "position")
extra_kwargs = {"pk": {"read_only": False}}
class StepListSerializer(serializers.ListSerializer):
child = StepSerializer()
def update(self, instance, validated_data):
...
from rest_framework.generics import GenericAPIView
from .models import Step
from .serializers import StepListSerializer
class StepUpdateAPIView(GenericAPIView):
model = Step
serializer_class = StepListSerializer
def post(self, request, *args, **kwargs):
serializer = self.get_serializer(self.get_queryset(), data=request.data)
serializer.is_valid(raise_exception=True)
serializer.save()
return Response(serializer.data) |
@srtab that looks like reasonable usage. i fixed the exception and added ListSerializer handling for explicit usage. |
@tfranzel That's perfect! Thanks for the fast response! |
you're welcome and thank you! |
Hi,
I'm using a
ListSerializer
in my views and when I try to load do openapi, just raise the following exception:ListSerializer
doesn't havefields
attribute, but can be extracted fromchild
attribute. Do you think that makes sensedrf-spectacular
to support this kind of serializers too?The text was updated successfully, but these errors were encountered: