drf-spectacular icon indicating copy to clipboard operation
drf-spectacular copied to clipboard

Error: Missing Serializer Class in Custom Destroy View

Open lidyum opened this issue 4 months ago • 0 comments

Description:

I encountered an error while using a custom class that extends generics.DestroyAPIView. The error message is as follows:

/usr/local/lib/python3.8/site-packages/betik_app_person/views/relation_ship_type.py: Error: exception raised while getting serializer. Hint: Is get_serializer_class() returning None or is get_queryset() not working without a request? Ignoring the view for now. (Exception: 'CustomDestroyView' should either include a `serializer_class` attribute, or override the `get_serializer_class()` method.)

Expected Behavior:

In general, a view extending DestroyAPIView should not require a serializer. The primary function of DestroyAPIView is to handle DELETE requests, and it is expected that the deletion operation can be performed without needing a serializer class for validation or serialization of input data.

Current Behavior:

Despite this expectation, the error indicates that the custom destroy view is missing a serializer_class attribute or is not properly implementing the get_serializer_class() method. This requirement seems contradictory to the expected functionality of DestroyAPIView.

Questions:

  • Why does this custom view, which extends DestroyAPIView, require a serializer class?
  • Is there a specific condition or configuration in the Django REST Framework that mandates a serializer for delete operations, even when input validation or data serialization is not necessary?

Additional Context:

  • Django REST Framework version: [insert your DRF version]
  • Any relevant code snippets or configurations that may help in diagnosing the issue.

Thank you for your assistance!

lidyum avatar Oct 16 '24 17:10 lidyum