Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch APIException in doc generation #5443

Merged
merged 1 commit into from
Sep 25, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions rest_framework/schemas/inspectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
See schemas.__init__.py for package overview.
"""
import re
import warnings
from collections import OrderedDict

from django.db import models
from django.utils.encoding import force_text, smart_text
from django.utils.translation import ugettext_lazy as _

from rest_framework import serializers
from rest_framework import exceptions, serializers
from rest_framework.compat import coreapi, coreschema, uritemplate, urlparse
from rest_framework.settings import api_settings
from rest_framework.utils import formatting
Expand Down Expand Up @@ -285,7 +286,14 @@ def get_serializer_fields(self, path, method):
if not hasattr(view, 'get_serializer'):
return []

serializer = view.get_serializer()
try:
serializer = view.get_serializer()
except exceptions.APIException:
serializer = None
Copy link
Collaborator

@carltongibson carltongibson Sep 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need a warning here. Something like

"""
{}.get_serializer() raised an exception during schema 
generation. 
Serializer fields will not be generated for {} {}.
""".format(view.cls.__name__, method, path)

(The formatting there is more for GitHub than the code.)

This way we'll have some kind of console feedback so users can address any issues.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, added a warning.

warnings.warn('{}.get_serializer() raised an exception during '
'schema generation. Serializer fields will not be '
'generated for {} {}.'.format(
type(view), method, path))

if isinstance(serializer, serializers.ListSerializer):
return [
Expand Down