File tree 2 files changed +30
-1
lines changed
2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -356,7 +356,15 @@ def check_throttles(self, request):
356
356
throttle_durations .append (throttle .wait ())
357
357
358
358
if throttle_durations :
359
- self .throttled (request , max (throttle_durations ))
359
+ # Filter out `None` values which may happen in case of config / rate
360
+ # changes, see #1438
361
+ durations = [
362
+ duration for duration in throttle_durations
363
+ if duration is not None
364
+ ]
365
+
366
+ duration = max (durations , default = None )
367
+ self .throttled (request , duration )
360
368
361
369
def determine_version (self , request , * args , ** kwargs ):
362
370
"""
Original file line number Diff line number Diff line change @@ -159,6 +159,27 @@ def test_request_throttling_multiple_throttles(self):
159
159
assert response .status_code == 429
160
160
assert int (response ['retry-after' ]) == 58
161
161
162
+ def test_throttle_rate_change_negative (self ):
163
+ self .set_throttle_timer (MockView_DoubleThrottling , 0 )
164
+ request = self .factory .get ('/' )
165
+ for dummy in range (24 ):
166
+ response = MockView_DoubleThrottling .as_view ()(request )
167
+ assert response .status_code == 429
168
+ assert int (response ['retry-after' ]) == 60
169
+
170
+ previous_rate = User3SecRateThrottle .rate
171
+ try :
172
+ User3SecRateThrottle .rate = '1/sec'
173
+
174
+ for dummy in range (24 ):
175
+ response = MockView_DoubleThrottling .as_view ()(request )
176
+
177
+ assert response .status_code == 429
178
+ assert int (response ['retry-after' ]) == 60
179
+ finally :
180
+ # reset
181
+ User3SecRateThrottle .rate = previous_rate
182
+
162
183
def ensure_response_header_contains_proper_throttle_field (self , view , expected_headers ):
163
184
"""
164
185
Ensure the response returns an Retry-After field with status and next attributes
You can’t perform that action at this time.
0 commit comments