mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-22 01:26:53 +03:00
Fix error in throttling when request.user is None (#8370)
Check to see if request.user is set before proceeding with further authentication checks.
This commit is contained in:
parent
2051a79da3
commit
129890ab1b
|
@ -171,7 +171,7 @@ class AnonRateThrottle(SimpleRateThrottle):
|
||||||
scope = 'anon'
|
scope = 'anon'
|
||||||
|
|
||||||
def get_cache_key(self, request, view):
|
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 None # Only throttle unauthenticated requests.
|
||||||
|
|
||||||
return self.cache_format % {
|
return self.cache_format % {
|
||||||
|
@ -191,7 +191,7 @@ class UserRateThrottle(SimpleRateThrottle):
|
||||||
scope = 'user'
|
scope = 'user'
|
||||||
|
|
||||||
def get_cache_key(self, request, view):
|
def get_cache_key(self, request, view):
|
||||||
if request.user.is_authenticated:
|
if request.user and request.user.is_authenticated:
|
||||||
ident = request.user.pk
|
ident = request.user.pk
|
||||||
else:
|
else:
|
||||||
ident = self.get_ident(request)
|
ident = self.get_ident(request)
|
||||||
|
@ -239,7 +239,7 @@ class ScopedRateThrottle(SimpleRateThrottle):
|
||||||
Otherwise generate the unique cache key by concatenating the user id
|
Otherwise generate the unique cache key by concatenating the user id
|
||||||
with the `.throttle_scope` property of the view.
|
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
|
ident = request.user.pk
|
||||||
else:
|
else:
|
||||||
ident = self.get_ident(request)
|
ident = self.get_ident(request)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user