Skip to content

Commit 0b91183

Browse files
Reapply "Merge remote-tracking branch 'upstream/sea-migration' into decouple-session"
This reverts commit bdb8381. Signed-off-by: varun-edachali-dbx <[email protected]>
1 parent d8159e7 commit 0b91183

File tree

5 files changed

+43
-6
lines changed

5 files changed

+43
-6
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
# the repo. Unless a later match takes precedence, these
33
# users will be requested for review when someone opens a
44
# pull request.
5-
* @deeksha-db @samikshya-db @jprakash-db @yunbodeng-db @jackyhu-db @benc-db
5+
* @deeksha-db @samikshya-db @jprakash-db @jackyhu-db @madhav-db @gopalldb @jayantsing-db @vikrantpuppala @shivam2680

src/databricks/sql/backend/thrift_backend.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,13 @@ def __init__(
138138
# max_download_threads
139139
# Number of threads for handling cloud fetch downloads. Defaults to 10
140140

141+
logger.debug(
142+
"ThriftBackend.__init__(server_hostname=%s, port=%s, http_path=%s)",
143+
server_hostname,
144+
port,
145+
http_path,
146+
)
147+
141148
port = port or 443
142149
if kwargs.get("_connection_uri"):
143150
uri = kwargs.get("_connection_uri")
@@ -409,6 +416,8 @@ def attempt_request(attempt):
409416

410417
# TODO: don't use exception handling for GOS polling...
411418

419+
logger.error("ThriftBackend.attempt_request: HTTPError: %s", err)
420+
412421
gos_name = TCLIServiceClient.GetOperationStatus.__name__
413422
if method.__name__ == gos_name:
414423
delay_default = (
@@ -453,6 +462,7 @@ def attempt_request(attempt):
453462
else:
454463
logger.warning(log_string)
455464
except Exception as err:
465+
logger.error("ThriftBackend.attempt_request: Exception: %s", err)
456466
error = err
457467
retry_delay = extract_retry_delay(attempt)
458468
error_message = (
@@ -942,6 +952,12 @@ def execute_command(
942952
thrift_handle,
943953
)
944954

955+
logger.debug(
956+
"ThriftBackend.execute_command(operation=%s, session_handle=%s)",
957+
operation,
958+
session_handle,
959+
)
960+
945961
spark_arrow_types = ttypes.TSparkArrowTypes(
946962
timestampAsArrow=self._use_arrow_native_timestamps,
947963
decimalAsArrow=self._use_arrow_native_decimals,

src/databricks/sql/client.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,12 @@ def read(self) -> Optional[OAuthToken]:
217217
# use_cloud_fetch
218218
# Enable use of cloud fetch to extract large query results in parallel via cloud storage
219219

220+
logger.debug(
221+
"Connection.__init__(server_hostname=%s, http_path=%s)",
222+
server_hostname,
223+
http_path,
224+
)
225+
220226
if access_token:
221227
access_token_kv = {"access_token": access_token}
222228
kwargs = {**kwargs, **access_token_kv}
@@ -292,7 +298,13 @@ def __enter__(self) -> "Connection":
292298
return self
293299

294300
def __exit__(self, exc_type, exc_value, traceback):
295-
self.close()
301+
try:
302+
self.close()
303+
except BaseException as e:
304+
logger.warning(f"Exception during connection close in __exit__: {e}")
305+
if exc_type is None:
306+
raise
307+
return False
296308

297309
def __del__(self):
298310
if self.open:
@@ -415,7 +427,14 @@ def __enter__(self) -> "Cursor":
415427
return self
416428

417429
def __exit__(self, exc_type, exc_value, traceback):
418-
self.close()
430+
try:
431+
logger.debug("Cursor context manager exiting, calling close()")
432+
self.close()
433+
except BaseException as e:
434+
logger.warning(f"Exception during cursor close in __exit__: {e}")
435+
if exc_type is None:
436+
raise
437+
return False
419438

420439
def __iter__(self):
421440
if self.active_result_set:
@@ -746,6 +765,9 @@ def execute(
746765
747766
:returns self
748767
"""
768+
logger.debug(
769+
"Cursor.execute(operation=%s, parameters=%s)", operation, parameters
770+
)
749771

750772
param_approach = self._determine_parameter_approach(parameters)
751773
if param_approach == ParameterApproach.NONE:

tests/e2e/test_driver.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050

5151
from tests.e2e.common.uc_volume_tests import PySQLUCVolumeTestSuiteMixin
5252

53-
from databricks.sql.exc import SessionAlreadyClosedError
53+
from databricks.sql.exc import SessionAlreadyClosedError, CursorAlreadyClosedError
5454

5555
log = logging.getLogger(__name__)
5656

@@ -820,7 +820,6 @@ def test_close_connection_closes_cursors(self):
820820
ars = cursor.active_result_set
821821

822822
# We must manually run this check because thrift_backend always forces `has_been_closed_server_side` to True
823-
824823
# Cursor op state should be open before connection is closed
825824
status_request = ttypes.TGetOperationStatusReq(
826825
operationHandle=ars.command_id.to_thrift_handle(),
@@ -846,7 +845,6 @@ def test_closing_a_closed_connection_doesnt_fail(self, caplog):
846845
with self.connection() as conn:
847846
# First .close() call is explicit here
848847
conn.close()
849-
850848
assert "Session appears to have been closed already" in caplog.text
851849

852850
conn = None

tests/unit/test_client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import databricks.sql
2121
import databricks.sql.client as client
2222
from databricks.sql import InterfaceError, DatabaseError, Error, NotSupportedError
23+
from databricks.sql.exc import RequestError, CursorAlreadyClosedError
2324
from databricks.sql.types import Row
2425
from databricks.sql.client import CommandId
2526

0 commit comments

Comments
 (0)