Closed daidaitaotao closed 4 years ago
Thanks @daidaitaotao for pointing this out, it's definitely a bug, I guess I forgot to handle this case.
Thanks for hunting it down too you made it so easy for me to fix it.
Hi, @yezyilomo thank you for the quick reply and thank you for helping us.
Hello,
I recently encounter an issue with using NestedModelSerializer for updating a nested field. I am wondering if it is a bug.
For example, I have the nested serializer set up this way:
I could create a
property
object throughPropertySerializer
without pass in alocation
data due to the fact that is not required.Later on, I decided to patch a
location
into thisproperty
with request payload likeI noticed the
location
object has been created but it is not attached to theproperty
.I did a little research and found out it may be related to some logic in
django_restql.mixins.NestedUpdateMixin.update_writable_foreignkey_related
.In this code above, if the
nested_obj
did not exist, it will not attach the newly createdobj
back toinstance
. I wonder if it has been done intentionally? If so, I wonder what is the reason, and is there a proper way to patch a nested object into a parent object that did not originally exist?Thank you!