diff --git a/rest_framework/fields.py b/rest_framework/fields.py index 8aced6a9c8..ef5dd995a1 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -1754,7 +1754,10 @@ def get_value(self, dictionary): # We override the default field access in order to support # dictionaries in HTML forms. if html.is_html_input(dictionary): - return html.parse_html_dict(dictionary, prefix=self.field_name) + value = html.parse_html_dict(dictionary, prefix=self.field_name) + if not value and getattr(self.root, 'partial', False): + return empty + return value 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 b8b1e4caf7..c1746043ba 100644 --- a/tests/test_fields.py +++ b/tests/test_fields.py @@ -2522,6 +2522,14 @@ def test_allow_empty_disallowed(self): assert exc_info.value.detail == ['This dictionary may not be empty.'] + def test_partial_update_does_not_include_missing_html_dict_field(self): + class TestSerializer(serializers.Serializer): + field_name = serializers.DictField(required=False) + + serializer = TestSerializer(data=QueryDict(''), partial=True) + assert serializer.is_valid() + assert 'field_name' not in serializer.validated_data + class TestNestedDictField(FieldValues): """