Fix parsing multipart data using a nested serializer with list #3820
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Parsing multipart data using a nested serializer with a list can result in incorrect behavior. If the list contains more than one item, only the last item will be saved.
Here is an example:
When you send the following data formatted as JSON everything will be fine:
However, when you send the same data formatted as multipart data the serialized object will only take the last element of the list:
The bug is situated in
parse_html_dict(dictionary, prefix='')
inrest_framework.utils.html
. This function takes and returns a newMultiValueDict
. A key in aMultiValueDict
can have multiple values, this is how a list is represented. When accessing a key in aMultiValueDict
only the last element of the list is returned.This can be easily solved by using .getlist() and .setlist() when getting and setting the value of the
MultiValueDict
.Closes #3710.