master branch of Django REST framework.Hi! Thanks for maintaining this library! I'm attempting to upgrade a project that has existing API documentation from DRF 3.9.4 to DRF 3.10.0 and I'm encountering the following error message when trying to use AutoSchema:
AttributeError at /api/docs/
'AutoSchema' object has no attribute 'get_link'
I've attempted to reduce it to its most minimal form by removing all the places where we are subclassing AutoSchema but I still encounter the error when trying to load the documentation.
For background: our docs are presented using Django-REST-Swagger, and I also updated the statement which imports AutoSchema from
from rest_framework.schemas.inspectors import AutoSchema
to
from rest_framework.schemas.coreapi import AutoSchema
I may just be missing the right incantation to say to get this to work. Do you have any suggestions on having this upgrade work without having to undertake substantial code changes?
Upgrading from 3.9.4 to 3.10.0 does not break existing API documentation.
Upgrading from 3.9.4 to 3.10.0 does break existing API documentation.
The built-in docs are not compatible with the new OpenAPI schema generation. Nor will they be. You'll need to move to one of the (many) options for generating docs with OpenAPI. A couple of these options are listed on the Documenting your API topic page.
The existing docs, and legacy CoreAPI support, will continue to function, but you should migrate to OpenAPI as soon as possible. See the 3.10 release announcement for instructions on Continuing to use CoreAPI.
Sorry, I misread: you're using Django-REST-Swagger. More or less you'll still need to follow the "Continuing to use..." advice. I'd guess the error comes from the default where you're NOT subclassing. (Hence the setting for the default...)
Maybe there'll need to be additional changes in Django-REST-Swagger but I can't say about that...
Thanks so much for the rapid response! Setting the DEFAULT_SCHEMA_CLASS to use CoreAPI as indicated in the docs you linked made everything work without having to change the code.
Thanks again for maintaining this library!
I'd guess the error comes from the default where you're NOT subclassing.
This seemed to be true, btw -- commenting out all our subclasses still showed the error prior to adjusting the DEFAULT_SCHEMA_CLASS.
this worked for me too, thanks @carltongibson
Same again, cheers Carlton!
Good to see it's working! (A moderate amount of effort went into maintaining BC, with this one setting change. So 馃拑)
Just as a thought, if any of you have a suggestion for the release announcement that would have emphasised what we have there to save you the trip here, that might be worth a PR.
if any of you have a suggestion for the release announcement that would have emphasised what we have there to save you the trip here, that might be worth a PR.
Great suggestion. In retrospect I think there were two hurdles to finding and understanding this:
https://www.django-rest-framework.org/community/3.10-announcement/#continuing-to-use-coreapi
I knew that the docs setup was incompatible with OpenAPI, but I didn't readily know that the format we were using was CoreAPI -- mostly because we maintain another app that uses and older version of DRF & Django-REST-Swagger that used inline YAML docstrings for the documentation.
I initially checked the release notes here https://www.django-rest-framework.org/community/release-notes/#3100 to find them but didn't see the CoreAPI mention.
Incidentally, I also tried to figure it out using this documentation page -- https://www.django-rest-framework.org/coreapi/schemas/ -- which is what made me try to update the AutoSchema import to come from coreapi rather than inspectors. Would it make sense to update the Schemas documentation page to have some mention of the DEFAULT_SCHEMA_CLASS setting for CoreAPI compatibility for version 3.10? If so I can create a PR to add this section.
Yeah, super. (You鈥檙e in the best position to suggest edits, being on the sharp end so to speak. 馃檪). Thanks!
I'm sorry I got this error and I don't know anything about Django docs. Everytime since I started using Django and DRF the docs just magically appear on /docs/. What do I have to do to un-break it after upgrading to DRF3.10?
By adding "default_schema_class" it worked for me.
REST_FRAMEWORK = {
...
'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema'
}
I had issue with swagger with following dependencies:
Django==3.0.3
django-rest-swagger==2.2.0
djangorestframework==3.11.0
The error was:
AttributeError: 'AutoSchema' object has no attribute 'get_link'
It solves by adding this line to settings.py:
REST_FRAMEWORK = {'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema'}
Then error was:
In template /Users/egorkrasilnikov/Desktop/python-rest-api-hard/venv/lib/python3.8/site-packages/rest_framework_swagger/templates/rest_framework_swagger/index.html, error at line 2
'staticfiles' is not a registered tag library
Use nano or vim in terminal and change{% load staticfiles %} to {% load static %} in above file path
Then Swagger works fine
I had issue with swagger with following dependencies:
Django==3.0.3
django-rest-swagger==2.2.0
djangorestframework==3.11.0
The error was:AttributeError: 'AutoSchema' object has no attribute 'get_link'
It solves by adding this line to settings.py:
REST_FRAMEWORK = {'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema'}
Then error was:In template /Users/egorkrasilnikov/Desktop/python-rest-api-hard/venv/lib/python3.8/site-packages/rest_framework_swagger/templates/rest_framework_swagger/index.html, error at line 2
'staticfiles' is not a registered tag libraryUse nano or vim in terminal and change
{% load staticfiles %}to{% load static %}in above file pathThen Swagger works fine
This is not a good way to do it.
Instead you have to create a directory inside your templates with name rest_framework_swagger and add a file named index.html and replace all it's contents with https://github.com/marcgibbons/django-rest-swagger/blob/master/rest_framework_swagger/templates/rest_framework_swagger/index.html
Most helpful comment
By adding "default_schema_class" it worked for me.
REST_FRAMEWORK = {
...
'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema'
}