Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Update Token Authentication sections to explain how to properly… #648

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dontic
Copy link

@dontic dontic commented Aug 19, 2024

… disable it

Background (can be skipped)

Just as an FYI for anyone who might be looking for this exact issue.

I was using drf-spectacular together with dj-rest-auth and was getting a constant error:

File "/root/.local/share/virtualenvs/facturing-be-yU94o058/lib/python3.11/site-packages/rest_framework/utils/model_meta.py", line 35, in get_field_info
    opts = model._meta.concrete_model._meta
           ^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute '_meta'

The problem was that I was not using Token Authentication but rather Session Authentication, and thus, following the docs, I set TOKEN_MODEL to None.

The problem comes when the TokenSerializer is still active, and tries to get the Token model, which is overridden by the TOKEN_MODEL setting. This causes the error above.

Fix

To properly disable Token Authentication, the TOKEN_SERIALIZER setting should also be set to None, together with TOKEN_MODEL.

I've added a couple of notes under TOKEN_SERIALIZER and TOKEN_MODEL specifying that both need to be set to None in order to fully disable the Token Authentication functionality.

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

Successfully merging this pull request may close these issues.

1 participant