Skip to content

3.9: AttributeError when Schema Endpoint requires authentication #6258

@0asys

Description

@0asys

Checklist

  • I have verified that that issue exists against the master branch of Django REST framework.
  • I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
  • This is not a usage question. (Those should be directed to the discussion group instead.)
  • This cannot be dealt with as a third party library. (We prefer new functionality to be in the form of third party libraries where possible.)
  • I have reduced the issue to the simplest possible case.
  • I have included a failing test as a pull request. (If you are unable to do so we can still accept the issue.)

Steps to reproduce

from rest_framework.schemas import get_schema_view

schema_view = get_schema_view(
    title='Server Monitoring API',
    url='https://www.example.org/api/'
)

urlpatterns = [
    url('^schema.json$', schema_view),
]
  • Set Permission IsAuthenticated:
REST_FRAMEWORK = {
    'DEFAULT_PERMISSION_CLASSES': (
        'rest_framework.permissions.IsAuthenticated',
    ),
  • Open /schema.json

Expected behavior

  • Authorization Error

Actual behavior

Internal Server Error: /schema.json
Traceback (most recent call last):
  File "./.venv/lib/python3.6/site-packages/django/core/handlers/exception.py", line 35, in inner
    response = get_response(request)
  File "./.venv/lib/python3.6/site-packages/django/core/handlers/base.py", line 158, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "./.venv/lib/python3.6/site-packages/django/core/handlers/base.py", line 156, in _get_response
    response = response.render()
  File "./.venv/lib/python3.6/site-packages/django/template/response.py", line 106, in render
    self.content = self.rendered_content
  File "./.venv/lib/python3.6/site-packages/rest_framework/response.py", line 72, in rendered_content
    ret = renderer.render(self.data, accepted_media_type, context)
  File "./.venv/lib/python3.6/site-packages/rest_framework/renderers.py", line 732, in render
    context = self.get_context(data, accepted_media_type, renderer_context)
  File "./.venv/lib/python3.6/site-packages/rest_framework/renderers.py", line 687, in get_context
    'content': self.get_content(renderer, data, accepted_media_type, renderer_context),
  File "./.venv/lib/python3.6/site-packages/rest_framework/renderers.py", line 423, in get_content
    content = renderer.render(data, accepted_media_type, renderer_context)
  File "./.venv/lib/python3.6/site-packages/rest_framework/renderers.py", line 1036, in render
    structure = self.get_structure(data)
  File "./.venv/lib/python3.6/site-packages/rest_framework/renderers.py", line 1016, in get_structure
    'title': data.title,
AttributeError: 'dict' object has no attribute 'title'
.venv/lib/python3.6/site-packages/rest_framework/renderers.py in get_structure
data = {'detail': ErrorDetail(string='Authentication credentials were not provided.', code='not_authenticated')}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions