mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-02 19:40:13 +03:00
Revert "Non-required fields with 'allow_null=True' should not imply a default value (#5639)"
This reverts commit 905a5579df
.
Closes #5708
This commit is contained in:
parent
7bb92d3ba5
commit
8d2ac40658
|
@ -442,10 +442,10 @@ class Field(object):
|
|||
except (KeyError, AttributeError) as exc:
|
||||
if self.default is not empty:
|
||||
return self.get_default()
|
||||
if not self.required:
|
||||
raise SkipField()
|
||||
if self.allow_null:
|
||||
return None
|
||||
if not self.required:
|
||||
raise SkipField()
|
||||
msg = (
|
||||
'Got {exc_type} when attempting to get a value for field '
|
||||
'`{field}` on serializer `{serializer}`.\nThe serializer '
|
||||
|
|
|
@ -384,14 +384,6 @@ 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