diff --git a/rest_framework/fields.py b/rest_framework/fields.py index 8d339e798..5a3ea5c8e 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -1391,7 +1391,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) 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):