mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-02 11:30:12 +03:00
Add test for allow_null + required=False
Ref #5708: allow_null should imply default=None, even for non-required fields. flake8
This commit is contained in:
parent
12569f83c9
commit
7bb92d3ba5
|
@ -486,12 +486,16 @@ class TestDefaultOutput:
|
|||
assert Serializer({'nested': {'a': '3', 'b': {'c': '4'}}}).data == {'nested': {'a': '3', 'c': '4'}}
|
||||
|
||||
def test_default_for_allow_null(self):
|
||||
# allow_null=True should imply default=None
|
||||
"""
|
||||
Without an explicit default, allow_null implies default=None when serializing. #5518 #5708
|
||||
"""
|
||||
class Serializer(serializers.Serializer):
|
||||
foo = serializers.CharField()
|
||||
bar = serializers.CharField(source='foo.bar', allow_null=True)
|
||||
optional = serializers.CharField(required=False, allow_null=True)
|
||||
|
||||
assert Serializer({'foo': None}).data == {'foo': None, 'bar': None}
|
||||
# allow_null=True should imply default=None when serialising:
|
||||
assert Serializer({'foo': None}).data == {'foo': None, 'bar': None, 'optional': None, }
|
||||
|
||||
|
||||
class TestCacheSerializerData:
|
||||
|
|
Loading…
Reference in New Issue
Block a user