From d80b317b6a0a5b30bb861e78ecbf702de8dd113c Mon Sep 17 00:00:00 2001 From: JasperSui Date: Thu, 22 Jul 2021 14:47:32 +0800 Subject: [PATCH] Intialize self.history if only the key is not in cache --- rest_framework/throttling.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/rest_framework/throttling.py b/rest_framework/throttling.py index dd4f062b4..3d29ab7bf 100644 --- a/rest_framework/throttling.py +++ b/rest_framework/throttling.py @@ -121,7 +121,10 @@ class SimpleRateThrottle(BaseThrottle): if self.key is None: return True - self.history = self.cache.get(self.key, deque()) + self.history = self.cache.get(self.key) + if self.history is None: + self.history = deque() + self.now = self.timer() # Drop any requests from the history which have now passed the