Check for None before calling to_representation

Django REST Framework also does this in serializers.

https://github.com/encode/django-rest-framework/issues/2299
4d57d46bf8/rest_framework/serializers.py (L518)

Fixes #203.
openapi3
Cristi Vîjdea 2018-09-09 22:22:58 +03:00
parent f9b215deab
commit 5fa35d5b81
1 changed files with 1 additions and 1 deletions

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;