Skip to content

Commit 8d8f730

Browse files
nearly working SEA retries
Signed-off-by: varun-edachali-dbx <varun.edachali@databricks.com>
1 parent e32c858 commit 8d8f730

File tree

7 files changed

+538
-210
lines changed

7 files changed

+538
-210
lines changed

src/databricks/sql/auth/thrift_http_client.py

Lines changed: 36 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -283,92 +283,46 @@ def make_rest_request(
283283
# Log request details (debug level)
284284
logger.debug(f"Making {method} request to {full_path}")
285285

286-
try:
287-
# Make request using the connection pool
288-
logger.debug(f"making request to {full_path}")
289-
logger.debug(f"\trequest headers: {request_headers}")
290-
logger.debug(f"\trequest body: {body.decode('utf-8') if body else None}")
291-
logger.debug(f"\trequest params: {params}")
292-
logger.debug(f"\trequest full path: {full_path}")
293-
self.__resp = self.__pool.request(
294-
method,
295-
url=full_path,
296-
body=body,
297-
headers=request_headers,
298-
preload_content=False,
299-
timeout=self.__timeout,
300-
retries=self.retry_policy,
301-
)
302-
303-
# Store response status and headers
304-
if self.__resp is not None:
305-
self.code = self.__resp.status
306-
self.message = self.__resp.reason
307-
self.headers = self.__resp.headers
308-
309-
# Log response status
310-
logger.debug(f"Response status: {self.code}, message: {self.message}")
311-
312-
# Read and parse response data
313-
# Note: urllib3's HTTPResponse has a data attribute, but it's not in the type stubs
314-
response_data = getattr(self.__resp, "data", None)
315-
316-
# Check for HTTP errors
317-
self._check_rest_response_for_error(self.code, response_data)
318-
319-
# Parse JSON response if there is content
320-
if response_data:
321-
result = json.loads(response_data.decode("utf-8"))
322-
323-
# Log response content (truncated for large responses)
324-
content_str = json.dumps(result)
325-
logger.debug(f"Response content: {content_str}")
326-
327-
return result
286+
# Make request using the connection pool - let urllib3 exceptions propagate
287+
logger.debug(f"making request to {full_path}")
288+
logger.debug(f"\trequest headers: {request_headers}")
289+
logger.debug(f"\trequest body: {body.decode('utf-8') if body else None}")
290+
logger.debug(f"\trequest params: {params}")
291+
logger.debug(f"\trequest full path: {full_path}")
292+
self.__resp = self.__pool.request(
293+
method,
294+
url=full_path,
295+
body=body,
296+
headers=request_headers,
297+
preload_content=False,
298+
timeout=self.__timeout,
299+
retries=self.retry_policy,
300+
)
301+
logger.debug(f"Response: {self.__resp}")
328302

329-
return {}
330-
else:
331-
raise ValueError("No response received from server")
303+
# Store response status and headers
304+
if self.__resp is not None:
305+
self.code = self.__resp.status
306+
self.message = self.__resp.reason
307+
self.headers = self.__resp.headers
332308

333-
except urllib3.exceptions.HTTPError as e:
334-
error_message = f"REST HTTP request failed: {str(e)}"
335-
logger.error(error_message)
336-
from databricks.sql.exc import RequestError
309+
# Log response status
310+
logger.debug(f"Response status: {self.code}, message: {self.message}")
337311

338-
raise RequestError(error_message, e)
312+
# Read and parse response data
313+
# Note: urllib3's HTTPResponse has a data attribute, but it's not in the type stubs
314+
response_data = getattr(self.__resp, "data", None)
339315

340-
def _check_rest_response_for_error(
341-
self, status_code: int, response_data: Optional[bytes]
342-
) -> None:
343-
"""
344-
Check if the REST response indicates an error and raise an appropriate exception.
316+
# Parse JSON response if there is content
317+
if response_data:
318+
result = json.loads(response_data.decode("utf-8"))
345319

346-
Args:
347-
status_code: HTTP status code
348-
response_data: Raw response data
320+
# Log response content (truncated for large responses)
321+
content_str = json.dumps(result)
322+
logger.debug(f"Response content: {content_str}")
349323

350-
Raises:
351-
RequestError: If the response indicates an error
352-
"""
353-
if status_code >= 400:
354-
error_message = f"REST HTTP request failed with status {status_code}"
324+
return result
355325

356-
# Try to extract error details from JSON response
357-
if response_data:
358-
try:
359-
error_details = json.loads(response_data.decode("utf-8"))
360-
if isinstance(error_details, dict) and "message" in error_details:
361-
error_message = f"{error_message}: {error_details['message']}"
362-
logger.error(
363-
f"Request failed (status {status_code}): {error_details}"
364-
)
365-
except (ValueError, KeyError):
366-
# If we can't parse JSON, log raw content
367-
content = response_data.decode("utf-8", errors="replace")
368-
logger.error(f"Request failed (status {status_code}): {content}")
369-
else:
370-
logger.error(f"Request failed (status {status_code}): No response data")
371-
372-
from databricks.sql.exc import RequestError
373-
374-
raise RequestError(error_message)
326+
return {}
327+
else:
328+
raise ValueError("No response received from server")

src/databricks/sql/backend/filters.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919

2020
from databricks.sql.backend.types import ExecuteResponse, CommandId
2121
from databricks.sql.backend.sea.models.base import ResultData
22-
from databricks.sql.backend.sea.backend import SeaDatabricksClient
2322

2423
if TYPE_CHECKING:
24+
from databricks.sql.backend.sea.backend import SeaDatabricksClient
2525
from databricks.sql.result_set import ResultSet, SeaResultSet
2626

2727
logger = logging.getLogger(__name__)
@@ -78,6 +78,8 @@ def _filter_sea_result_set(
7878
result_data = ResultData(data=filtered_rows, external_links=None)
7979

8080
# Create a new SeaResultSet with the filtered data
81+
from databricks.sql.backend.sea.backend import SeaDatabricksClient
82+
8183
filtered_result_set = SeaResultSet(
8284
connection=result_set.connection,
8385
execute_response=execute_response,

0 commit comments

Comments
 (0)