Skip to content

Commit 98fc645

Browse files
committed
[PECO-1687] Fixed the issue of infinite blocking in case of invalid credentials
1 parent a5b1ab0 commit 98fc645

File tree

9 files changed

+63
-1
lines changed

9 files changed

+63
-1
lines changed

.idea/.gitignore

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/codeStyles/Project.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/codeStyles/codeStyleConfig.xml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/databricks-sql-python.iml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/databricks/sql/auth/retry.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
MaxRetryDurationError,
2020
NonRecoverableNetworkError,
2121
OperationalError,
22+
AuthenticationFailureError,
2223
SessionAlreadyClosedError,
2324
UnsafeToRetryError,
2425
)
@@ -326,7 +327,7 @@ def should_retry(self, method: str, status_code: int) -> Tuple[bool, str]:
326327
This limit prevents automatically retrying non-idempotent commands that could
327328
be destructive.
328329
5. The request received a 403 response, because this can never succeed.
329-
330+
6. The request received a 401 response, because the User credentials are invalid
330331
331332
Q: What about OSErrors and Redirects?
332333
A: urllib3 automatically retries in both scenarios
@@ -339,6 +340,11 @@ def should_retry(self, method: str, status_code: int) -> Tuple[bool, str]:
339340
if status_code == 200:
340341
return False, "200 codes are not retried"
341342

343+
# Don't retry as there is an authentication error
344+
if status_code == 401:
345+
raise AuthenticationFailureError(
346+
"Received 401 - UNAUTHORIZED. Authentication is required and has failed or has not yet been provided."
347+
)
342348
if status_code == 403:
343349
raise NonRecoverableNetworkError(
344350
"Received 403 - FORBIDDEN. Confirm your authentication credentials."

src/databricks/sql/exc.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ class NonRecoverableNetworkError(RequestError):
105105
"""Thrown if an HTTP code 501 is received"""
106106

107107

108+
class AuthenticationFailureError(RequestError):
109+
"""Thrown if an HTTP code 401 is received"""
110+
111+
108112
class UnsafeToRetryError(RequestError):
109113
"""Thrown if ExecuteStatement request receives a code other than 200, 429, or 503"""
110114

0 commit comments

Comments
 (0)