diff --git a/rest_framework/fields.py b/rest_framework/fields.py index 85c451078..e49e4cbfb 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -1083,7 +1083,11 @@ class MultipleChoiceField(ChoiceField): # We override the default field access in order to support # lists in HTML forms. if html.is_html_input(dictionary): - return dictionary.getlist(self.field_name) + ret = dictionary.getlist(self.field_name) + if getattr(self.root, 'partial', False) and not ret: + ret = empty + return ret + return dictionary.get(self.field_name, empty) def to_internal_value(self, data): diff --git a/tests/test_fields.py b/tests/test_fields.py index 6a523bba2..5a5ad4af7 100644 --- a/tests/test_fields.py +++ b/tests/test_fields.py @@ -1,6 +1,7 @@ from decimal import Decimal from django.utils import timezone from rest_framework import serializers +import rest_framework import datetime import django import pytest @@ -1038,6 +1039,15 @@ class TestMultipleChoiceField(FieldValues): ] ) + def test_against_partial_and_full_updates(self): + # serializer = self.Serializer(data=MockHTMLDict()) + from django.http import QueryDict + field = serializers.MultipleChoiceField(choices=(('a', 'a'), ('b', 'b'))) + field.partial = False + assert field.get_value(QueryDict({})) == [] + field.partial = True + assert field.get_value(QueryDict({})) == rest_framework.fields.empty + # File serializers...