-
Notifications
You must be signed in to change notification settings - Fork 274
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
Schema fails to build with serializer method fields that reference an overridden list serializer #694
Comments
Hi @mwhansen, first of all thanks for the detailed explanation. This is such a specific circumstance that I don't think I would have found it without it. Apparently this is only broken when With that construction you snug by all the override resolution guards and - as you rightly noted - we then walk past the override in
Yes I noticed. Although that change is functionally identical, I'm not sure yet if we want to have that. I have to think about how to resolve this optimally. |
Thanks for taking a look! It's not a block now since we can manually use the schema directly rather than through the indirection. |
Interesting. I thought the error is due to the fact that this decorator works on a Serializer class, not an instance of a Serializer. Can we solve this by passing a second optional parameter to this function to determine if it should be a list or not instead of the Serializer itself? |
@uroybd the decorators take both serializer class and serializer instance. Instance is usually used to signal a list with Adding a extra parameter for this case would be weird, as this behavior is consistent over the whole API. |
Describe the bug
Sorry the title is not the greatest! When annotating a
SerializerMethodField
with a list serializer where the child is overridden with@extend_schema_field
, then the schema fails to build, erroring out withTo Reproduce
We can update
test_extend_schema.py
with the following to reproduce the error:This is happening since we get a call trace like:
_map_response_type_hint
is called while processing theSerializerMethodField
self._unwrap_list_serializer(field, direction)
is called on onInlineWithOverrideSerializer(many=True)
_unwrap_list_serializer
onInlineWithOverrideSerializer()
self.resolve_serializer(...)
is called onInlineWithOverrideSerializer()
component.schema = self._map_serializer(serializer, direction)
is called to build the schema from the serializer fields directly;component.schema
isNone
, this is component discarded andResolvedComponent(None, None)
is returned fromresolve_serializer
schema=None
to be returned to theSerializerMethodField
handlingappend_meta(None, meta)
which causes the error.Note: This does not happen if we do
@extend_schema_field(InlineWithOverrideSerializer)
(without themany=True
.)It seems like we should check for overrides and extensions during the
_unwrap_list_serializer
, but I'm not sure the best place as putting_map_serializer_field
within_unwrap_list_serializer
causes some additional changes like:Expected behavior
I would expect the schema to build and the schema for the
SerializerMethodField
to be an array ofOtherInlineSerializer
components.The text was updated successfully, but these errors were encountered: