mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-03 12:00:12 +03:00
Merge 4c6b3c64ac
into 12569f83c9
This commit is contained in:
commit
dc70005b01
|
@ -442,6 +442,8 @@ class Field(object):
|
||||||
except (KeyError, AttributeError) as exc:
|
except (KeyError, AttributeError) as exc:
|
||||||
if self.default is not empty:
|
if self.default is not empty:
|
||||||
return self.get_default()
|
return self.get_default()
|
||||||
|
if self.read_only and self.allow_null:
|
||||||
|
return None
|
||||||
if not self.required:
|
if not self.required:
|
||||||
raise SkipField()
|
raise SkipField()
|
||||||
if self.allow_null:
|
if self.allow_null:
|
||||||
|
|
|
@ -387,10 +387,16 @@ class TestNotRequiredOutput:
|
||||||
def test_not_required_output_for_allow_null_field(self):
|
def test_not_required_output_for_allow_null_field(self):
|
||||||
class ExampleSerializer(serializers.Serializer):
|
class ExampleSerializer(serializers.Serializer):
|
||||||
omitted = serializers.CharField(required=False, allow_null=True)
|
omitted = serializers.CharField(required=False, allow_null=True)
|
||||||
|
ommited_read_only = serializers.CharField(
|
||||||
|
required=False,
|
||||||
|
read_only=True,
|
||||||
|
allow_null=True
|
||||||
|
)
|
||||||
included = serializers.CharField()
|
included = serializers.CharField()
|
||||||
|
|
||||||
serializer = ExampleSerializer({'included': 'abc'})
|
serializer = ExampleSerializer({'included': 'abc'})
|
||||||
assert 'omitted' not in serializer.data
|
assert 'omitted' not in serializer.data
|
||||||
|
assert serializer.data['ommited_read_only'] is None
|
||||||
|
|
||||||
|
|
||||||
class TestDefaultOutput:
|
class TestDefaultOutput:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user