You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have reduced the issue to the simplest possible case.
I have included a failing test as a pull request. (If you are unable to do so we can still accept the issue.)
Steps to reproduce
According to the OP on this Stack Overflow question, submitting a list as multipart/formdata, and then running it through a validator returns a list with a string containing all of the fields, instead of a list of the fields.
Set up a DFR website.
Upload data encoded as multipart/formdata
Run it through a ListField validator.
Expected behavior
Data submitted as multipart/formdata and then validated should be returned as a list.
Actual behavior
The output of the validation is an array of a single string.
Notes
I don't know what versions of Python/Django/DRF the OP was using, but I'm using Django 1.9.4, and DRF 3.3.2.
Users = ['x1','x2']
In my serializer create method I try to iterate over them:
users = validated_data.get('users', None)
for user in users:
print(user)
print("===")
The output I receive is:
x1,x2
===
In my answer there, I traced through the ListField and the ListSerializer and guessed (correctly) that the to_representation method in the serializer was flattening the data.
It's a bit to vague for me to process.
As far as I remember, ListSerializer don't work with html forms - might be wrong here, not sure at all. ListField will work if one had a multiple select widget.
Do you have some code sample we could run ?
The issue isn't actionnable in its current form and nobody seems to step forward and write a test case for it.
I'll reconsider opening it when provided with a failing test case to demonstrate the issue.
Checklist
master
branch of Django REST framework.Steps to reproduce
According to the OP on this Stack Overflow question, submitting a list as
multipart/formdata
, and then running it through a validator returns a list with a string containing all of the fields, instead of a list of the fields.Expected behavior
Data submitted as
multipart/formdata
and then validated should be returned as a list.Actual behavior
The output of the validation is an array of a single string.
Notes
I don't know what versions of Python/Django/DRF the OP was using, but I'm using Django 1.9.4, and DRF 3.3.2.
The original conversation was here: http://stackoverflow.com/q/36696285/224988
From the OP:
In my answer there, I traced through the
ListField
and theListSerializer
and guessed (correctly) that theto_representation
method in the serializer was flattening the data.Is this the intended behavior?
Possibly related issues: #3685, #3864, #3970
The text was updated successfully, but these errors were encountered: