Skip to content

Commit 4afff39

Browse files
account for max_redirects in SEA backend
Signed-off-by: varun-edachali-dbx <varun.edachali@databricks.com>
1 parent 3e55ddd commit 4afff39

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/databricks/sql/backend/sea/utils/http_client.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from urllib3 import HTTPConnectionPool, HTTPSConnectionPool, ProxyManager
1010
from urllib3.util import make_headers
11+
from urllib3.exceptions import MaxRetryError
1112

1213
from databricks.sql.auth.authenticators import AuthProvider
1314
from databricks.sql.auth.retry import CommandType, DatabricksRetryPolicy
@@ -98,14 +99,23 @@ def __init__(
9899
self.enable_v3_retries = kwargs.get("_enable_v3_retries", True)
99100

100101
if self.enable_v3_retries:
102+
urllib3_kwargs = {"allowed_methods": ["GET", "POST", "DELETE"]}
103+
_max_redirects = kwargs.get("_retry_max_redirects")
104+
if _max_redirects:
105+
if _max_redirects > self._retry_stop_after_attempts_count:
106+
logger.warning(
107+
"_retry_max_redirects > _retry_stop_after_attempts_count so it will have no affect!"
108+
)
109+
urllib3_kwargs["redirect"] = _max_redirects
110+
101111
self.retry_policy = DatabricksRetryPolicy(
102112
delay_min=self._retry_delay_min,
103113
delay_max=self._retry_delay_max,
104114
stop_after_attempts_count=self._retry_stop_after_attempts_count,
105115
stop_after_attempts_duration=self._retry_stop_after_attempts_duration,
106116
delay_default=self._retry_delay_default,
107117
force_dangerous_codes=self.force_dangerous_codes,
108-
urllib3_kwargs={"allowed_methods": ["GET", "POST", "DELETE"]},
118+
urllib3_kwargs=urllib3_kwargs,
109119
)
110120
else:
111121
# Legacy behavior - no automatic retries
@@ -275,6 +285,18 @@ def _make_request(
275285
error_message = f"Request failed: {e}"
276286
# Construct RequestError with proper 3-argument format (message, context, error) like Thrift backend
277287
raise RequestError(error_message, None, e)
288+
except MaxRetryError as e:
289+
# urllib3 MaxRetryError should bubble up for redirect tests to catch
290+
# Don't convert to RequestError, let the test framework handle it
291+
logger.error(f"SEA HTTP request failed with MaxRetryError: {e}")
292+
raise
293+
except Exception as e:
294+
# Broad exception handler like Thrift backend to catch any unexpected errors
295+
# (including test mocking issues like StopIteration)
296+
logger.error(f"SEA HTTP request failed with exception: {e}")
297+
error_message = f"Error during request to server. {e}"
298+
# Construct RequestError with proper 3-argument format (message, context, error) like Thrift backend
299+
raise RequestError(error_message, None, e)
278300

279301
logger.debug(f"Response status: {response.status}")
280302

0 commit comments

Comments
 (0)