drf-writable-nested icon indicating copy to clipboard operation
drf-writable-nested copied to clipboard

Reverse relations not working for serializers with many=True

Open oxan opened this issue 6 years ago • 5 comments

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.

oxan avatar Sep 17 '19 19:09 oxan

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.

TJHeeringa avatar Dec 05 '20 12:12 TJHeeringa

also come across this bug frequency + 1

JintGuo avatar Dec 14 '20 14:12 JintGuo

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

pakal avatar Feb 26 '21 17:02 pakal

frequency + 1

dongchaotina avatar Apr 12 '21 13:04 dongchaotina

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

feelixe avatar Apr 15 '21 11:04 feelixe