Skip to content

Commit a61df99

Browse files
Reapply "Merge remote-tracking branch 'upstream/sea-migration' into decouple-session"
This reverts commit bdb8381. Signed-off-by: varun-edachali-dbx <varun.edachali@databricks.com>
1 parent 73649f2 commit a61df99

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
@@ -133,6 +133,13 @@ def __init__(
133133
# max_download_threads
134134
# Number of threads for handling cloud fetch downloads. Defaults to 10
135135

136+
logger.debug(
137+
"ThriftBackend.__init__(server_hostname=%s, port=%s, http_path=%s)",
138+
server_hostname,
139+
port,
140+
http_path,
141+
)
142+
136143
port = port or 443
137144
if kwargs.get("_connection_uri"):
138145
uri = kwargs.get("_connection_uri")
@@ -404,6 +411,8 @@ def attempt_request(attempt):
404411

405412
# TODO: don't use exception handling for GOS polling...
406413

414+
logger.error("ThriftBackend.attempt_request: HTTPError: %s", err)
415+
407416
gos_name = TCLIServiceClient.GetOperationStatus.__name__
408417
if method.__name__ == gos_name:
409418
delay_default = (
@@ -448,6 +457,7 @@ def attempt_request(attempt):
448457
else:
449458
logger.warning(log_string)
450459
except Exception as err:
460+
logger.error("ThriftBackend.attempt_request: Exception: %s", err)
451461
error = err
452462
retry_delay = extract_retry_delay(attempt)
453463
error_message = (
@@ -926,6 +936,12 @@ def execute_command(
926936
thrift_handle,
927937
)
928938

939+
logger.debug(
940+
"ThriftBackend.execute_command(operation=%s, session_handle=%s)",
941+
operation,
942+
session_handle,
943+
)
944+
929945
spark_arrow_types = ttypes.TSparkArrowTypes(
930946
timestampAsArrow=self._use_arrow_native_timestamps,
931947
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}
@@ -291,7 +297,13 @@ def __enter__(self) -> "Connection":
291297
return self
292298

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

296308
def __del__(self):
297309
if self.open:
@@ -414,7 +426,14 @@ def __enter__(self) -> "Cursor":
414426
return self
415427

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

419438
def __iter__(self):
420439
if self.active_result_set:
@@ -745,6 +764,9 @@ def execute(
745764
746765
:returns self
747766
"""
767+
logger.debug(
768+
"Cursor.execute(operation=%s, parameters=%s)", operation, parameters
769+
)
748770

749771
param_approach = self._determine_parameter_approach(parameters)
750772
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)