drf-spectacular: a problem with creating a schema with drf 3.10.3
Describe the bug
I have used drf version 3.10.3 as suggested and my previous problem has been resolved.
Alas, the schema still does not get built, failing with:
AssertionError: Incompatible AutoSchema used on View <class 'view-name'>. Is DRF's DEFAULT_SCHEMA_CLASS pointing to "drf_spectacular.openapi.AutoSchema" or any other drf-spectacular compatible AutoSchema?
This happens although I have set DEFAULT_SCHEMA_CLASS in REST_FRAMEWORK settings to drf_spectacular.openapi.AutoSchema.
To Reproduce create a project with drf 3.10.3 (Django 2.2, Python 3.8/3.9) Execute ./manage.py spectacular --file schema.yml
Expected behavior I would expect the schema to pass smoothly
The same applies to 3.11.2 drf version
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 22 (8 by maintainers)
Commits related to this issue
- mitigate DRF bug in ObtainAuthToken < 3.12.0 #796 — committed to tfranzel/drf-spectacular by tfranzel 4 years ago
- mitigate DRF bug in ObtainAuthToken < 3.12.0 #796 — committed to tfranzel/drf-spectacular by tfranzel 4 years ago
- Merge pull request #803 from tfranzel/obtainauthtoken mitigate DRF bug in ObtainAuthToken < 3.12.0 #796 — committed to tfranzel/drf-spectacular by tfranzel 4 years ago
Thanks @fannyhub for digging in. Sorry that I nudged you in the wrong direction repeatedly. 99% of raised&resolved issues were indeed wrong configs. I was not aware of that SO question and apparently nobody raised it here.
Your analysis is absolutely correct. It is indeed a bug in DRF < 3.12. I added an extension that fixes that bug for prior versions. It will be in the next release (
0.24.0). Until then, you can easily fix it yourself by emulating what the extension will do:and using that in your
urlpatternsinstead ofObtainAuthToken/obtain_auth_token. Or you could simply copy&paste that extension for the time being.Resolved, I had this
from drf_spectacular.openapi import AutoSchemain my import in settings.py. Removed it and everything works fineThat is the usual fallacy. running
./manage.py runserverand./manage.py shellmight load different settings depending on your setup. Sometimes simply by the prescence of a differentDJANGO_SETTINGS_MODULEenvironment variable. It is a common issue. Try to use the debugger on your actual webserver process if possible. I’m quite confident it will be different in there.I am glad my tip helped
On Sat, 1 Mar 2025, 12:26 pm Joshua Nwokoye (Atoms), < @.***> wrote:
Ah, I just set up a test project and it’s working. OK sorry about that, I’ll start going through my project and see where I messed up (starting with getting rid of drf-yasg).
On Thu, Feb 27, 2025 at 7:41 AM T. Franzel @.***> wrote:
Thank you, no more problems with creating schema 😃