Description
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.