Skip to content

ListField seems to miss single values #3235

@kezabelle

Description

@kezabelle

The get_value method of ListField seems to use if len(val) > 1: where I believe it ought to be if len(val) >= 1: or if len(val) > 0:

In a Django QueryDict, for example, getlist will yield a list of 1 item even if there is only one item. This seems to miss all the paths currently defined.

By way of example, here's a quick sketch of what I believe is demonstrable of the issue I think we're having:

>>> from rest_framework.fields import ListField
>>> from django.http import QueryDict
>>> qs = QueryDict('foo=1')
[u'1']
>>> qs2 = QueryDict('foo=1&foo=2')
[u'1', u'2']
>>> field = ListField()
>>> field.field_name = 'foo'  # for the purposes of getting the prefix right
>>> field.get_value(qs2)
[u'1', u'2']
>>> field.get_value(qs)
[]

I'd expect the last, empty list [] to be [u'1']
This is against drf 3.2.0 and Django 1.8.x

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy