From 08d60f5cc2ca1be2c58bca159853a0ee84f8b058 Mon Sep 17 00:00:00 2001 From: Keryn Knight Date: Fri, 7 Aug 2015 11:41:56 +0100 Subject: [PATCH 1/2] Refs #3235 - Test demonstrating a single value passed to ListField is lost. --- tests/test_fields.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/test_fields.py b/tests/test_fields.py index 0a67324ee..455b47ad2 100644 --- a/tests/test_fields.py +++ b/tests/test_fields.py @@ -317,6 +317,14 @@ class TestHTMLInput: assert serializer.is_valid() assert serializer.validated_data == {'scores': [1, 3]} + def test_querydict_list_input_only_one_input(self): + class TestSerializer(serializers.Serializer): + scores = serializers.ListField(child=serializers.IntegerField()) + + serializer = TestSerializer(data=QueryDict('scores=1&')) + assert serializer.is_valid() + assert serializer.validated_data == {'scores': [1]} + class TestCreateOnlyDefault: def setup(self): From 0078f661048fba5f71a44ee2d10334197f1181b7 Mon Sep 17 00:00:00 2001 From: Keryn Knight Date: Fri, 7 Aug 2015 11:43:17 +0100 Subject: [PATCH 2/2] Fixed #3235 - A querydict which yields a list with only one value now correctly returns the provided data. --- rest_framework/fields.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rest_framework/fields.py b/rest_framework/fields.py index 1d12b1d92..772f39e3d 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -1384,7 +1384,7 @@ class ListField(Field): # lists in HTML forms. if html.is_html_input(dictionary): val = dictionary.getlist(self.field_name, []) - if len(val) > 1: + if len(val) > 0: # Support QueryDict lists in HTML input. return val return html.parse_html_list(dictionary, prefix=self.field_name)