@@ -30,6 +30,7 @@ class CommandType(Enum):
3030 EXECUTE_STATEMENT = "ExecuteStatement"
3131 CLOSE_SESSION = "CloseSession"
3232 CLOSE_OPERATION = "CloseOperation"
33+ GET_OPERATION_STATUS = "GetOperationStatus"
3334 OTHER = "Other"
3435
3536 @classmethod
@@ -314,9 +315,9 @@ def should_retry(self, method: str, status_code: int) -> Tuple[bool, str]:
314315 2. The request received a 501 (Not Implemented) status code
315316 Because this request can never succeed.
316317 3. The request received a 404 (Not Found) code and the request CommandType
317- was CloseSession or CloseOperation. This code indicates that the session
318- or cursor was already closed. Further retries will always return the same
319- code.
318+ was GetOperationStatus, CloseSession or CloseOperation. This code indicates
319+ that the command, session or cursor was already closed. Further retries will
320+ always return the same code.
320321 4. The request CommandType was ExecuteStatement and the HTTP code does not
321322 appear in the default status_forcelist or force_dangerous_codes list. By
322323 default, this means ExecuteStatement is only retried for codes 429 and 503.
@@ -343,6 +344,13 @@ def should_retry(self, method: str, status_code: int) -> Tuple[bool, str]:
343344 if not self ._is_method_retryable (method ): # type: ignore
344345 return False , "Only POST requests are retried"
345346
347+ # Request failed with 404 and was a GetOperationStatus. This is not recoverable. Don't retry.
348+ if status_code == 404 and self .command_type == CommandType .GET_OPERATION_STATUS :
349+ return (
350+ False ,
351+ "GetOperationStatus received 404 code from Databricks. Operation was canceled." ,
352+ )
353+
346354 # Request failed with 404 because CloseSession returns 404 if you repeat the request.
347355 if (
348356 status_code == 404
0 commit comments