You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
I was extending my API and creating new serializers. After adding another one and regenerating the schema I encountered this error message:
Warning [FilledFormAnswerViewSet > FilledFormAnswerSerializer > FormQuestionSerializer]: Encountered 2 components with identical names "FormQuestionRequest" and different classes <class 'forms.serializers.FormQuestionSerializer'> and <class 'forms.serializers.FormQuestionRequestSerializer'>. This will very likely result in an incorrect schema. Try renaming one.
This error appears after I type-hint a SerializerMethodField.
Class structure is as follows:
class FormQuestionRequestMappingSerializer(serializers.Serializer):
label = serializers.CharField()
value = serializers.CharField()
class Meta:
fields = ("label", "value")
class FormQuestionRequestSerializer(serializers.Serializer):
url = serializers.CharField()
mapping = serializers.DictField(
child=FormQuestionRequestMappingSerializer(),
allow_empty=False,
)
params = serializers.DictField()
class Meta:
fields = ("url", "mapping", "params")
class FormQuestionSerializer(serializers.ModelSerializer):
choices = FormQuestionChoiceSerializer(many=True, read_only=True)
request_params = serializers.SerializerMethodField()
@extend_schema_field(FormQuestionRequestSerializer)
def get_request_params(self, obj):
if obj.data_type != QuestionDataType.REQUEST:
return None
return dict(
url=reverse(obj.request_field_route) if obj.request_field_route else None,
mapping={
"value": obj.request_field_mapping.get("value", "id"),
"label": obj.request_field_mapping.get("label", "title"),
},
request_params=obj.request_field_params,
)
class Meta:
model = FormQuestion
fields = (
"id",
"title",
"data_type",
"request_params",
)
And as soon as I rename FormQuestionRequestSerializer to NOT contain the exact "Request" word - the error is gone.
This serializer class name is unique in the project - so I am sure it does not clash with an existing one.
I also have a model class FormQuestion in my app, and maybe somehow that causes the name conflict, but I don't quite get how it may happen.
DRF-spectacular settings are as follows:
SPECTACULAR_SETTINGS = {
"TITLE": "API Project",
"DESCRIPTION": "API for my project",
"VERSION": "1.0.0",
"COMPONENT_SPLIT_REQUEST": True,
"POSTPROCESSING_HOOKS": [],
}
Expected behavior
Being able to name serializer classes without causing critical errors.
The text was updated successfully, but these errors were encountered:
Describe the bug
I was extending my API and creating new serializers. After adding another one and regenerating the schema I encountered this error message:
This error appears after I type-hint a SerializerMethodField.
Class structure is as follows:
And as soon as I rename FormQuestionRequestSerializer to NOT contain the exact "Request" word - the error is gone.
This serializer class name is unique in the project - so I am sure it does not clash with an existing one.
I also have a model class
FormQuestion
in my app, and maybe somehow that causes the name conflict, but I don't quite get how it may happen.DRF-spectacular settings are as follows:
Expected behavior
Being able to name serializer classes without causing critical errors.
The text was updated successfully, but these errors were encountered: