Skip to content

Add support for QueryDict data in serializers.ListField #3155

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

Closed
wants to merge 1 commit into from

Conversation

chank1012
Copy link

Failing case:

When user uploads multiple images (for example, <input type="file" name="image_files" multiple="">) and I try to serialize it with:

  • image_files = serializers.ListField(child=serializers.FileField(write_only=True))

Serializer fails to evaluate "list of files".

Problem:
https://github.com/tomchristie/django-rest-framework/blob/master/rest_framework/fields.py#L1273

    # Suppose dictionary.__class__ == QueryDict
    def get_value(self, dictionary):
        # dictionary has attribute 'getlist', so is_html_input returns True
        if html.is_html_input(dictionary):
            # but try to parse it as MultiDict
            return html.parse_html_list(dictionary, prefix=self.field_name)
        return dictionary.get(self.field_name, empty)

ListField class doesn't handle QueryDict-typed data properly.

Solution:

I haven't looked up for all codes related to this issue, so my PR is just a naive hotfix. I think there should be more consistent method to handle both QueryDict & MultiDict data types.

@tomchristie tomchristie added this to the 3.1.4 Release milestone Jul 16, 2015
@tomchristie
Copy link
Member

Now resolved - thanks for the report! Upcoming in the latest 3.1.4 release.

@chank1012 chank1012 deleted the listfield-for-querydict branch July 16, 2015 17:14
@tomchristie tomchristie modified the milestones: 3.1.4 Release, 3.2.0 Release Jul 30, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants