From 5fa35d5b8145b3a02ee6db3cc084b8f0b2c8effe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristi=20V=C3=AEjdea?= Date: Sun, 9 Sep 2018 22:22:58 +0300 Subject: [PATCH] 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. --- src/drf_yasg/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/drf_yasg/utils.py b/src/drf_yasg/utils.py index b900feb..4b09d25 100644 --- a/src/drf_yasg/utils.py +++ b/src/drf_yasg/utils.py @@ -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;