From d2a2783c95ba27737a4e517463bdc98295d82cf3 Mon Sep 17 00:00:00 2001 From: Krista Mae Rectra Date: Wed, 6 Jan 2021 13:22:43 +0000 Subject: [PATCH 1/2] Check for allow_null attribute --- src/drf_yasg/inspectors/base.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/drf_yasg/inspectors/base.py b/src/drf_yasg/inspectors/base.py index 5bc03243..c2f78266 100644 --- a/src/drf_yasg/inspectors/base.py +++ b/src/drf_yasg/inspectors/base.py @@ -281,8 +281,10 @@ def SwaggerType(existing_object=None, use_field_title=True, **instance_kwargs): instance_kwargs.setdefault('title', title) if description is not None: instance_kwargs.setdefault('description', description) - if field.allow_null: - instance_kwargs['x_nullable'] = True + + if hasattr(field, 'allow_null'): + if field.allow_null: + instance_kwargs['x_nullable'] = True instance_kwargs.update(kwargs) From 11fdb02291cac62da71983aebe3be1a16cb34f92 Mon Sep 17 00:00:00 2001 From: Krista Mae Rectra Date: Mon, 24 May 2021 07:06:03 +0000 Subject: [PATCH 2/2] simplify if condition --- src/drf_yasg/inspectors/base.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/drf_yasg/inspectors/base.py b/src/drf_yasg/inspectors/base.py index c2f78266..18875981 100644 --- a/src/drf_yasg/inspectors/base.py +++ b/src/drf_yasg/inspectors/base.py @@ -281,10 +281,9 @@ def SwaggerType(existing_object=None, use_field_title=True, **instance_kwargs): instance_kwargs.setdefault('title', title) if description is not None: instance_kwargs.setdefault('description', description) - - if hasattr(field, 'allow_null'): - if field.allow_null: - instance_kwargs['x_nullable'] = True + + if getattr(field, 'allow_null', None): + instance_kwargs['x_nullable'] = True instance_kwargs.update(kwargs)