Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is ListSerializer mishandling multipart/formdata uploads? #4056

Closed
5 of 6 tasks
MosheBerman opened this issue Apr 18, 2016 · 3 comments
Closed
5 of 6 tasks

Is ListSerializer mishandling multipart/formdata uploads? #4056

MosheBerman opened this issue Apr 18, 2016 · 3 comments

Comments

@MosheBerman
Copy link

MosheBerman commented Apr 18, 2016

Checklist

  • I have verified that that issue exists against the master branch of Django REST framework.
  • I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
  • This is not a usage question. (Those should be directed to the discussion group instead.)
  • This cannot be dealt with as a third party library. (We prefer new functionality to be in the form of third party libraries where possible.)
  • 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.

  1. Set up a DFR website.
  2. Upload data encoded as multipart/formdata
  3. 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.

The original conversation was here: http://stackoverflow.com/q/36696285/224988

From the OP:

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.

Is this the intended behavior?

Possibly related issues: #3685, #3864, #3970

@xordoquy
Copy link
Collaborator

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 ?

@rpkilby
Copy link
Member

rpkilby commented Dec 5, 2017

Was this fixed by #4181?

@xordoquy
Copy link
Collaborator

xordoquy commented Apr 17, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants