@@ -127,7 +127,7 @@ def __init__(
127
127
total = _attempts_remaining ,
128
128
respect_retry_after_header = True ,
129
129
backoff_factor = self .delay_min ,
130
- allowed_methods = ["POST" ],
130
+ allowed_methods = ["POST" , "DELETE" ], # Allow DELETE for CLOSE_SESSION and CLOSE_OPERATION
131
131
status_forcelist = [429 , 503 , * self .force_dangerous_codes ],
132
132
)
133
133
@@ -256,6 +256,13 @@ def delay_default(self) -> float:
256
256
"""
257
257
return self ._delay_default
258
258
259
+ def _is_method_retryable (self , method : str ) -> bool :
260
+ """Check if the given HTTP method is retryable.
261
+
262
+ We allow POST (for ExecuteStatement) and DELETE (for CloseSession/CloseOperation).
263
+ """
264
+ return method .upper () in ["POST" , "DELETE" ]
265
+
259
266
def start_retry_timer (self ) -> None :
260
267
"""Timer is used to monitor the overall time across successive requests
261
268
@@ -371,9 +378,9 @@ def should_retry(self, method: str, status_code: int) -> Tuple[bool, str]:
371
378
if status_code == 501 :
372
379
return False , "Received code 501 from server."
373
380
374
- # Request failed and this method is not retryable. We only retry POST requests.
381
+ # Request failed and this method is not retryable. We retry POST and DELETE requests.
375
382
if not self ._is_method_retryable (method ):
376
- return False , "Only POST requests are retried"
383
+ return False , "Only POST and DELETE requests are retried"
377
384
378
385
# Request failed with 404 and was a GetOperationStatus. This is not recoverable. Don't retry.
379
386
if status_code == 404 and self .command_type == CommandType .GET_OPERATION_STATUS :
0 commit comments