beda-software / drf-writable-nested

Writable nested model serializer for Django REST Framework
Other
1.07k stars 116 forks source link

Bug fix: prevent newly added (child) instances from being deleted soon after. #159

Open amartis opened 2 years ago

amartis commented 2 years ago

When the Bug is happening: This happens when the request was made as mutlipart-form. Where the request data is not multi-layer dictionary, but instead plain HTTP multipart-form.

Cause of Bug: The cause of the bug was the use of get_initial() to store primary keys (pk) in update_or_create_reverse_relations() get_initial() returns whole new object when the data is not nested dictionary but multipart-form where the key looks like profile[0]message_set[0]message And thus storing pk in that object is not persisted for delete_reverse_relations_if_need()

Solution: Use attribute nodelete_pks to persist the data.