beda-software / drf-writable-nested

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

Reverse relations not working for serializers with many=True #89

Open oxan opened 4 years ago

oxan commented 4 years ago

Serializers that are created with many=True have a list as initial_data. This results in get_initial() returning an empty dictionary. DRF doesn't seem interested in changing this on their end, see encode/django-rest-framework#5345.

The result of this is that the check in mixins.py:147 fails, and reverse relations (silently) aren't created or updated.

Not sure what's the best way to fix this (as behaviour on either side seems sensible), but it's clearly a bug.

TJHeeringa commented 3 years ago

This is the same with direct relations. With direct relations however this gives an error at https://github.com/beda-software/drf-writable-nested/blob/master/drf_writable_nested/mixins.py#L207.

JintGuo commented 3 years ago

also come across this bug frequency + 1

pakal commented 3 years ago

Same bug here, Iit seems that validated data should be fetched and transmitted to update...() methods, instead of being popped and deleted at lines like https://github.com/beda-software/drf-writable-nested/blob/master/drf_writable_nested/mixins.py#L36 ; thus there would be no need for self.get_initial() ; but lists of dicts will have to be treated separately

dongchaotina commented 3 years ago

frequency + 1

feelixe commented 3 years ago

I've made pull-request to fix this issue. Please consider reviewing code. https://github.com/beda-software/drf-writable-nested/pull/141

If you want to try it, here is my fork: https://github.com/Feelixe-tin/drf-writable-nested