Skip to content

Commit f3bc8a0

Browse files
potential working code dump
Signed-off-by: varun-edachali-dbx <[email protected]>
1 parent a9f2409 commit f3bc8a0

File tree

5 files changed

+590
-101
lines changed

5 files changed

+590
-101
lines changed

src/databricks/sql/auth/retry.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def __init__(
127127
total=_attempts_remaining,
128128
respect_retry_after_header=True,
129129
backoff_factor=self.delay_min,
130-
allowed_methods=["POST"],
130+
allowed_methods=["POST", "DELETE"], # Allow DELETE for CLOSE_SESSION and CLOSE_OPERATION
131131
status_forcelist=[429, 503, *self.force_dangerous_codes],
132132
)
133133

@@ -256,6 +256,13 @@ def delay_default(self) -> float:
256256
"""
257257
return self._delay_default
258258

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+
259266
def start_retry_timer(self) -> None:
260267
"""Timer is used to monitor the overall time across successive requests
261268
@@ -371,9 +378,9 @@ def should_retry(self, method: str, status_code: int) -> Tuple[bool, str]:
371378
if status_code == 501:
372379
return False, "Received code 501 from server."
373380

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.
375382
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"
377384

378385
# Request failed with 404 and was a GetOperationStatus. This is not recoverable. Don't retry.
379386
if status_code == 404 and self.command_type == CommandType.GET_OPERATION_STATUS:

0 commit comments

Comments
 (0)