-
Notifications
You must be signed in to change notification settings - Fork 301
Pass on instance when using polymorphic serializers #759
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
Labels
Comments
I have looked at the code as well and this seems invalid indeed. Usually this is not noticed as it only affects serializers which internally access PR is welcome. |
josebama
added a commit
to novastone-media/django-rest-framework-json-api
that referenced
this issue
Jan 22, 2020
5 tasks
sliverc
pushed a commit
to sliverc/django-rest-framework-json-api
that referenced
this issue
Jan 24, 2020
josebama
added a commit
to novastone-media/django-rest-framework-json-api
that referenced
this issue
Jan 27, 2020
sliverc
pushed a commit
that referenced
this issue
Jan 30, 2020
Fixes #759 Pass self.instance as the first parameter when initializing the child serializer from a polymorphic serialiser. This does not affect basic functionality, but makes the child serializer instance consistent with its usage of instance and data, which can fix potential issues when extending serilaizers that are part of a polymorphic serializer.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm trying to understand the code in
PolymorphicModelSerializer
and I wonder if this is a bug or me just not understanding something, but inPolymorphicModelSerializer.to_internal_value
, in the end, when in initsserializer_class
like so:return serializer_class(data, context=self.context, partial=self.partial).to_internal_value(data)
, why is it passingdata
as the first argument?For what I see, the init in
BaseSerializer
is expecting the first argument to beinstance
and the second one to bedata
:def __init__(self, instance=None, data=empty, **kwargs):
. Wouldn't it make more sense forPolymorphicModelSerializer.to_internal_value
to initserializer_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.The text was updated successfully, but these errors were encountered: