mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-10 19:56:59 +03:00
Non-required fields with 'allow_null=True' should not imply a default value (#5639)
Ref #5518.
This commit is contained in:
parent
97f7a82b37
commit
905a5579df
|
@ -442,10 +442,10 @@ class Field(object):
|
|||
except (KeyError, AttributeError) as exc:
|
||||
if self.default is not empty:
|
||||
return self.get_default()
|
||||
if self.allow_null:
|
||||
return None
|
||||
if not self.required:
|
||||
raise SkipField()
|
||||
if self.allow_null:
|
||||
return None
|
||||
msg = (
|
||||
'Got {exc_type} when attempting to get a value for field '
|
||||
'`{field}` on serializer `{serializer}`.\nThe serializer '
|
||||
|
|
|
@ -372,6 +372,14 @@ class TestNotRequiredOutput:
|
|||
serializer.save()
|
||||
assert serializer.data == {'included': 'abc'}
|
||||
|
||||
def test_not_required_output_for_allow_null_field(self):
|
||||
class ExampleSerializer(serializers.Serializer):
|
||||
omitted = serializers.CharField(required=False, allow_null=True)
|
||||
included = serializers.CharField()
|
||||
|
||||
serializer = ExampleSerializer({'included': 'abc'})
|
||||
assert 'omitted' not in serializer.data
|
||||
|
||||
|
||||
class TestDefaultOutput:
|
||||
def setup(self):
|
||||
|
|
Loading…
Reference in New Issue
Block a user