Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why swagger raises unclear error - Django

I have a django rest Backend app, and i use swagger to look and document my apis to the FE.

This worked fine, but I made some changes and now I get this error:

Internal Server Error: /
Traceback (most recent call last):
  File "/home/notsoshabby/.local/share/virtualenvs/panda_pitch-UBt5SNMA/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File "/home/notsoshabby/.local/share/virtualenvs/panda_pitch-UBt5SNMA/lib/python3.7/site-packages/django/core/handlers/base.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/home/notsoshabby/.local/share/virtualenvs/panda_pitch-UBt5SNMA/lib/python3.7/site-packages/django/core/handlers/base.py", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/notsoshabby/.local/share/virtualenvs/panda_pitch-UBt5SNMA/lib/python3.7/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "/home/notsoshabby/.local/share/virtualenvs/panda_pitch-UBt5SNMA/lib/python3.7/site-packages/django/views/generic/base.py", line 71, in view
    return self.dispatch(request, *args, **kwargs)
  File "/home/notsoshabby/.local/share/virtualenvs/panda_pitch-UBt5SNMA/lib/python3.7/site-packages/rest_framework/views.py", line 497, in dispatch
    response = self.handle_exception(exc)
  File "/home/notsoshabby/.local/share/virtualenvs/panda_pitch-UBt5SNMA/lib/python3.7/site-packages/rest_framework/views.py", line 457, in handle_exception
    self.raise_uncaught_exception(exc)
  File "/home/notsoshabby/.local/share/virtualenvs/panda_pitch-UBt5SNMA/lib/python3.7/site-packages/rest_framework/views.py", line 468, in raise_uncaught_exception
    raise exc
  File "/home/notsoshabby/.local/share/virtualenvs/panda_pitch-UBt5SNMA/lib/python3.7/site-packages/rest_framework/views.py", line 494, in dispatch
    response = handler(request, *args, **kwargs)
  File "/home/notsoshabby/.local/share/virtualenvs/panda_pitch-UBt5SNMA/lib/python3.7/site-packages/rest_framework_swagger/views.py", line 32, in get
    schema = generator.get_schema(request=request)
  File "/home/notsoshabby/.local/share/virtualenvs/panda_pitch-UBt5SNMA/lib/python3.7/site-packages/rest_framework/schemas/coreapi.py", line 153, in get_schema
    links = self.get_links(None if public else request)
  File "/home/notsoshabby/.local/share/virtualenvs/panda_pitch-UBt5SNMA/lib/python3.7/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'
HTTP GET / 500 [0.15, 127.0.0.1:44214]
/home/notsoshabby/Desktop/panda_pitch/django_project/settings.py 

This error is not very clear as the AutoSchema is not a part of my code and the traceback is not showing me where in My code the problem is. I made too many changes to go one by one and check which one caused that.

Anyone experienced this issue before? Any ideas on how to debug to find which change causes this issue?

like image 951
NotSoShabby Avatar asked Jul 20 '19 09:07

NotSoShabby


People also ask

Is Django rest swagger deprecated?

Django REST Swagger: deprecated (2019-06-04) This project is no longer being maintained.

Can I use swagger with Django?

Improved performance. Allow multiple instances of Swagger UI in a single Django project. Allow rendering the OpenAPI JSON spec independently. Improved control of authentication mechanisms.

How does Django integrate with swagger in Python?

Update settings.py file in main Django project to load django-rest-swagger app. Update urls.py file in main Django project to first load the get_swagger_view utility function and then add path to route to Swagger UI view. This is where the first hiccup rears it's head.

What is swagger in Django REST framework?

drf-yasg is a Swagger generation tool implemented without using the schema generation provided by Django Rest Framework. It aims to implement as much of the OpenAPI specification as possible - nested schemas, named models, response bodies, enum/pattern/min/max validators, form parameters, etc.


1 Answers

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' }
like image 98
Aseel Ashraf Avatar answered Oct 21 '22 05:10

Aseel Ashraf