Skip to content

Commit 552ba33

Browse files
committed
Catch APIException in doc generation
The documentation generator calls view.get_serializer() in order to inspect it for documentation generation. However, if get_serializer() throws an APIException (e.g. PermissionDenied), it doesn't get caught at the call site, but instead propagates up and aborts the entire view. With the try/except in this commit, the documentation generator instead gratiously ignores that particular view and moves on to the next one instead. Practical concequences of this commit is that the docs no longer break if any view's get_serializer(..) throws an APIException.
1 parent f6c19e5 commit 552ba33

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

rest_framework/schemas/inspectors.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from django.utils.encoding import force_text, smart_text
1111
from django.utils.translation import ugettext_lazy as _
1212

13+
from rest_framework import exceptions
1314
from rest_framework import serializers
1415
from rest_framework.compat import coreapi, coreschema, uritemplate, urlparse
1516
from rest_framework.settings import api_settings
@@ -285,7 +286,10 @@ def get_serializer_fields(self, path, method):
285286
if not hasattr(view, 'get_serializer'):
286287
return []
287288

288-
serializer = view.get_serializer()
289+
try:
290+
serializer = view.get_serializer()
291+
except exceptions.APIException:
292+
serializer = None
289293

290294
if isinstance(serializer, serializers.ListSerializer):
291295
return [

0 commit comments

Comments
 (0)