File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -356,7 +356,17 @@ 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
+ if durations :
367
+ self .throttled (request , max (durations ))
368
+ else :
369
+ self .throttled (request , None )
360
370
361
371
def determine_version (self , request , * args , ** kwargs ):
362
372
"""
Original file line number Diff line number Diff line change @@ -159,6 +159,26 @@ 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_handle_negative_throttle_value (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
+ User3SecRateThrottle .rate = '1/sec'
172
+
173
+ for dummy in range (24 ):
174
+ response = MockView_DoubleThrottling .as_view ()(request )
175
+
176
+ assert response .status_code == 429
177
+ assert int (response ['retry-after' ]) == 60
178
+
179
+ # reset
180
+ User3SecRateThrottle .rate = previous_rate
181
+
162
182
def ensure_response_header_contains_proper_throttle_field (self , view , expected_headers ):
163
183
"""
164
184
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