django-rest-swagger icon indicating copy to clipboard operation
django-rest-swagger copied to clipboard

'AutoSchema' object has no attribute 'get_link'

Open jhonatanTeixeira opened this issue 4 years ago • 4 comments

Hello, i got this configuration on my urls.py

from django.urls import path, include
from django.conf.urls import url
from rest_framework import routers
from .views import EnderecoViewSet
from rest_framework_swagger.views import get_swagger_view

router = routers.DefaultRouter()
router.register(r'enderecos', EnderecoViewSet)

schema_view = get_swagger_view(title='Pastebin API')

urlpatterns = [
    url(r'^$', schema_view),
    path('', include(router.urls)),
    path('api/', include('rest_framework.urls', namespace='rest_framework'))
]

However i get this error 'AutoSchema' object has no attribute 'get_link' when i visit localhost:8000/

heres the trace:

Traceback (most recent call last):
  File "C:\projects\pocs\python-pi\venv\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
    response = get_response(request)
  File "C:\projects\pocs\python-pi\venv\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "C:\projects\pocs\python-pi\venv\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\projects\pocs\python-pi\venv\lib\site-packages\django\views\decorators\csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "C:\projects\pocs\python-pi\venv\lib\site-packages\django\views\generic\base.py", line 71, in view
    return self.dispatch(request, *args, **kwargs)
  File "C:\projects\pocs\python-pi\venv\lib\site-packages\rest_framework\views.py", line 497, in dispatch
    response = self.handle_exception(exc)
  File "C:\projects\pocs\python-pi\venv\lib\site-packages\rest_framework\views.py", line 457, in handle_exception
    self.raise_uncaught_exception(exc)
  File "C:\projects\pocs\python-pi\venv\lib\site-packages\rest_framework\views.py", line 468, in raise_uncaught_exception
    raise exc
  File "C:\projects\pocs\python-pi\venv\lib\site-packages\rest_framework\views.py", line 494, in dispatch
    response = handler(request, *args, **kwargs)
  File "C:\projects\pocs\python-pi\venv\lib\site-packages\rest_framework_swagger\views.py", line 32, in get
    schema = generator.get_schema(request=request)
  File "C:\projects\pocs\python-pi\venv\lib\site-packages\rest_framework\schemas\coreapi.py", line 153, in get_schema
    links = self.get_links(None if public else request)
  File "C:\projects\pocs\python-pi\venv\lib\site-packages\rest_framework\schemas\coreapi.py", line 140, in get_links
    link = view.schema.get_link(path, method, base_url=self.url)
AttributeError: 'AutoSchema' object has no attribute 'get_link'
[17/Jul/2019 11:43:53] "GET / HTTP/1.1" 500 17187

what am i doing wrong?

jhonatanTeixeira avatar Jul 17 '19 14:07 jhonatanTeixeira

I ran into the same issue, the fix is described here: https://www.django-rest-framework.org/community/3.10-announcement/

To summarize, Django Rest Framework 3.10 (released a few days ago) deprecated the CoreAPI based schema generation, and introduced the OpenAPI schema generation in its place. Currently to continue to use django-rest-swagger as is you need to re-enable the CoreAPI schema generation by adding the following config to the settings file:

REST_FRAMEWORK = { ... 'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema' }

bmildren avatar Jul 18 '19 12:07 bmildren

Actually it looks like this project is deprecated so the better answer might be to switch to drf_yasg, this looks to work fine without the additional config.

bmildren avatar Jul 18 '19 12:07 bmildren

@jhonatanTeixeira Last activity seems to be 9 months ago... so seems like this wont be updated anymore. @bmildren Thanks for the info in drf_yasg. Seems to work right out of the box without issues!

jroeland avatar Aug 20 '19 14:08 jroeland

@jhonatanTeixeira could you adjust the title to say something about DRF >=3.10? Thank you!

hartwork avatar Jun 17 '20 19:06 hartwork