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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions rest_framework/throttling.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class AnonRateThrottle(SimpleRateThrottle):
scope = 'anon'

def get_cache_key(self, request, view):
if request.user.is_authenticated:
if request.user and request.user.is_authenticated:
return None # Only throttle unauthenticated requests.

return self.cache_format % {
Expand All @@ -191,7 +191,7 @@ class UserRateThrottle(SimpleRateThrottle):
scope = 'user'

def get_cache_key(self, request, view):
if request.user.is_authenticated:
if request.user and request.user.is_authenticated:
ident = request.user.pk
else:
ident = self.get_ident(request)
Expand Down Expand Up @@ -239,7 +239,7 @@ def get_cache_key(self, request, view):
Otherwise generate the unique cache key by concatenating the user id
with the '.throttle_scope` property of the view.
"""
if request.user.is_authenticated:
if request.user and request.user.is_authenticated:
ident = request.user.pk
else:
ident = self.get_ident(request)
Expand Down