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:
Cristi Vîjdea
2018-09-09 22:22:58 +03:00
parent f9b215deab
commit 5fa35d5b81
+1 -1
View File
@@ -404,7 +404,7 @@ def get_field_default(field):
"called; 'default' will not be set on schema", field, exc_info=True)
default = serializers.empty
if default is not serializers.empty:
if default is not serializers.empty and default is not None:
try:
default = field.to_representation(default)
# JSON roundtrip ensures that the value is valid JSON;