Skip to content
This repository has been archived by the owner on Jan 11, 2021. It is now read-only.

'AutoSchema' object has no attribute 'get_link' #808

Open
jhonatanTeixeira opened this issue Jul 17, 2019 · 4 comments
Open

'AutoSchema' object has no attribute 'get_link' #808

jhonatanTeixeira opened this issue Jul 17, 2019 · 4 comments

Comments

@jhonatanTeixeira
Copy link

jhonatanTeixeira commented Jul 17, 2019

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?

@bmildren
Copy link

bmildren commented Jul 18, 2019

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
Copy link

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.

@jroeland
Copy link

@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!

@hartwork
Copy link

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants