Catch and log exceptions raised from get_serializer

Fixes #135
openapi3
Cristi Vîjdea 2018-06-01 16:21:14 +03:00
parent 58adbb8f4c
commit 2ef7cfbfe3
1 changed files with 8 additions and 1 deletions

View File

@ -1,3 +1,4 @@
import logging
from collections import OrderedDict from collections import OrderedDict
from rest_framework.request import is_form_media_type from rest_framework.request import is_form_media_type
@ -12,6 +13,8 @@ from ..utils import (
) )
from .base import ViewInspector from .base import ViewInspector
log = logging.getLogger(__name__)
class SwaggerAutoSchema(ViewInspector): class SwaggerAutoSchema(ViewInspector):
def __init__(self, view, path, method, components, request, overrides): def __init__(self, view, path, method, components, request, overrides):
@ -83,7 +86,11 @@ class SwaggerAutoSchema(ViewInspector):
""" """
if not hasattr(self.view, 'get_serializer'): if not hasattr(self.view, 'get_serializer'):
return None return None
return self.view.get_serializer() try:
return self.view.get_serializer()
except Exception:
log.warning("view's get_serializer raised exception (%s)", type(self.view).__name__, exc_info=True)
return None
def get_request_serializer(self): def get_request_serializer(self):
"""Return the request serializer (used for parsing the request payload) for this endpoint. """Return the request serializer (used for parsing the request payload) for this endpoint.