[Fixed]-Drf-spectacular is using the wrong AutoSchema to generate Swagger


Please update the Django Rest Framework 3.11 to 3.12 it will work.


I have the same issue when I had REST_FRAMEWORK two times written for different settings in my settings.py. I moved everything in one variable and error is gone



If the AssertionError is about DRF’s ObtainAuthToken then it is most likely an old bug in DRF. This issue was fixed in DRF>=3.12. Prior to that, DRF used a wrong class where it was not supposed to.

drf-yasg seems to not suffer from this upstream bug due to a different injection technique used. drf-spectacular has a mitigation for the bug starting with 0.24.0.

Related GH issue with workaround for older drf-spectacular versions:

Sidenote: If this does not fix your problem and/or it is the same Assertion for some other view, you likely have a misconfigured settings.py. Make sure DEFAULT_SCHEMA_CLASS is properly set as stated in the README. Also make sure you are not shooting yourself in the foot by not setting this also in your production settings file. If the problem still persists, please open an issue on Github and get help there.



Check if you’re importing from rest_framework!

Having a

from rest_framework.pagination import PageNumberPagination

was all it took to provoke the error. As soon as I removed the import, things started working again.

This even applies when importing other modules which in turn import from rest_framework. I ended up using the "string imports" like so:

"DEFAULT_PAGINATION_CLASS": "api.pagination.DefaultPagination",


I had the same issue. Just make sure you don’t have REST_FRAMEWORK defined more than once in your settings.py file.

Leave a comment