Skip to content

Pass on instance when using polymorphic serializers #759

Closed
@josebama

Description

@josebama

I'm trying to understand the code in PolymorphicModelSerializer and I wonder if this is a bug or me just not understanding something, but in PolymorphicModelSerializer.to_internal_value, in the end, when in inits serializer_class like so: return serializer_class(data, context=self.context, partial=self.partial).to_internal_value(data), why is it passing data as the first argument?

For what I see, the init in BaseSerializer is expecting the first argument to be instance and the second one to be data: def __init__(self, instance=None, data=empty, **kwargs):. Wouldn't it make more sense for PolymorphicModelSerializer.to_internal_value to init serializer_class this other way: return serializer_class(self.instance, data, context=self.context, partial=self.partial).to_internal_value(data)?

That way the child serializer will keep the instance if there is any and will set the initial_data too.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions