yezyilomo / django-restql

Turn your API made with Django REST Framework(DRF) into a GraphQL like API.
https://yezyilomo.github.io/django-restql
MIT License
620 stars 43 forks source link

Parent object not saved after the nested object is assigned to it #300

Closed sommelon closed 2 years ago

sommelon commented 2 years ago

When I'm trying to update an object (Course) by creating a new nested object (Instructor), the created object is returned in the initial response to the PATCH request, but on a subsequent GET request, the nested object is still null. This is my test case

This line in the source code patches the parent object, but the parent itself is not saved. That explains the presence of the nested object in the response to the initial request. Tested with PUT and PATCH and the result is the same.

Not sure if a simple instance.save() after the line would be a proper fix.

yezyilomo commented 2 years ago

You are very right, it's a bug, I forgot to include instance.save() after updating an instance. The line you mentioned is the reason for a bug as well as this one. A temporary set was tricking tests :smile: that's why it was hard to hunt it down unless you recheck by sending a subsequent GET request as you did in your test.

Thank you very much for reporting this and taking your time to go through the source code to look for the problem.