mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-02-02 20:54:42 +03:00
Merge pull request #2993 from linovia/bug/2894
MultipleChoiceField empties incorrectly on a partial update using multipart/form-data (#2894)
This commit is contained in:
commit
f8eacc5bc0
|
@ -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):
|
||||
|
|
|
@ -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...
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user