Check for None before calling to_representation
Django REST Framework also does this in serializers. https://github.com/encode/django-rest-framework/issues/2299 https://github.com/encode/django-rest-framework/blob/4d57d46bf89f54f276909219ee06f0a2bf112f9f/rest_framework/serializers.py#L518 Fixes #203.
This commit is contained in:
@@ -404,7 +404,7 @@ def get_field_default(field):
|
|||||||
"called; 'default' will not be set on schema", field, exc_info=True)
|
"called; 'default' will not be set on schema", field, exc_info=True)
|
||||||
default = serializers.empty
|
default = serializers.empty
|
||||||
|
|
||||||
if default is not serializers.empty:
|
if default is not serializers.empty and default is not None:
|
||||||
try:
|
try:
|
||||||
default = field.to_representation(default)
|
default = field.to_representation(default)
|
||||||
# JSON roundtrip ensures that the value is valid JSON;
|
# JSON roundtrip ensures that the value is valid JSON;
|
||||||
|
|||||||
Reference in New Issue
Block a user