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

Fix error in throttling when request.user is None #8370

Merged

Conversation

4nickel
Copy link
Contributor

@4nickel 4nickel commented Feb 17, 2022

While trying to remove the Django authentication module, I've ran into an error when using the configuration below.
Specifically, an AttributeError is raised because DRF does not expect the user to be None.

# settings.py
REST_FRAMEWORK = {
    ...
    "DEFAULT_THROTTLE_CLASSES": (
        "rest_framework.throttling.AnonRateThrottle",
    ),
    "DEFAULT_THROTTLE_RATES": {"anon": "10000/day"},
    'DEFAULT_AUTHENTICATION_CLASSES': [],
    'DEFAULT_PERMISSION_CLASSES': [],
    'UNAUTHENTICATED_USER': None,
}

This PR fixes the issue by checking if request.user is set before proceeding with further authentication checks.
The test suite and pre-commit hooks are passing. If needed, I'll be happy to write a test-case for this.

As this is my first contribution to DRF please let me know in case I am missing any contribution guidelines. I'd like for the process to be as seamless as possible.

Thank you for your time and consideration.

Check to see if request.user is set before proceeding with further
authentication checks.
@shredding
Copy link

This affects me as well. Is there a chance to merge that soon?

@alexgutjahr
Copy link

+1

@stale
Copy link

stale bot commented Jun 23, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jun 23, 2022
@tomchristie
Copy link
Member

Normally you'd expect an UnauthenticatedUser instance in this case, but I don't have any objections to this.

@tomchristie tomchristie merged commit 129890a into encode:master Jun 24, 2022
@stale stale bot removed the stale label Jun 24, 2022
@4nickel 4nickel deleted the fix/allow-none-user-in-throttling branch June 27, 2022 08:55
sigvef pushed a commit to sigvef/django-rest-framework that referenced this pull request Dec 3, 2022
Check to see if request.user is set before proceeding with further
authentication checks.
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.

5 participants