Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
- Fix: Revised SQLAlchemy dialect and examples for compatibility with SQLAlchemy==1.3.x (#173)
- Fix: oauth would fail if expired credentials appeared in ~/.netrc (#122)
- Fix: Python HTTP proxies were broken after switch to urllib3 (#158)
- Other: Relax pandas dependency constraint to allow ^2.0.0 (#164)
- Other: Connector now logs operation handle guids as hexadecimal instead of bytes (#170)

## 2.7.0 (2023-06-26)

Expand Down
2 changes: 1 addition & 1 deletion src/databricks/sql/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def __del__(self):
if self.open:
logger.debug(
"Closing unclosed connection for session "
"{}".format(self.get_session_id())
"{}".format(self.get_session_id_hex())
)
try:
self._close(close_cursors=False)
Expand Down
39 changes: 34 additions & 5 deletions src/databricks/sql/thrift_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,24 +532,29 @@ def _check_command_not_in_error_or_closed_state(
raise ServerOperationError(
get_operations_resp.displayMessage,
{
"operation-id": op_handle and op_handle.operationId.guid,
"operation-id": op_handle
and self.guid_to_hex_id(op_handle.operationId.guid),
"diagnostic-info": get_operations_resp.diagnosticInfo,
},
)
else:
raise ServerOperationError(
get_operations_resp.errorMessage,
{
"operation-id": op_handle and op_handle.operationId.guid,
"operation-id": op_handle
and self.guid_to_hex_id(op_handle.operationId.guid),
"diagnostic-info": None,
},
)
elif get_operations_resp.operationState == ttypes.TOperationState.CLOSED_STATE:
raise DatabaseError(
"Command {} unexpectedly closed server side".format(
op_handle and op_handle.operationId.guid
op_handle and self.guid_to_hex_id(op_handle.operationId.guid)
),
{"operation-id": op_handle and op_handle.operationId.guid},
{
"operation-id": op_handle
and self.guid_to_hex_id(op_handle.operationId.guid)
},
)

def _poll_for_status(self, op_handle):
Expand Down Expand Up @@ -942,7 +947,11 @@ def close_command(self, op_handle):
return resp.status

def cancel_command(self, active_op_handle):
logger.debug("Cancelling command {}".format(active_op_handle.operationId.guid))
logger.debug(
"Cancelling command {}".format(
self.guid_to_hex_id(active_op_handle.operationId.guid)
)
)
req = ttypes.TCancelOperationReq(active_op_handle)
self.make_request(self._client.CancelOperation, req)

Expand All @@ -954,3 +963,23 @@ def handle_to_id(session_handle):
def handle_to_hex_id(session_handle: TCLIService.TSessionHandle):
this_uuid = uuid.UUID(bytes=session_handle.sessionId.guid)
return str(this_uuid)

@staticmethod
def guid_to_hex_id(guid: bytes) -> str:
"""Return a hexadecimal string instead of bytes

Example:
IN b'\x01\xee\x1d)\xa4\x19\x1d\xb6\xa9\xc0\x8d\xf1\xfe\xbaB\xdd'
OUT '01ee1d29-a419-1db6-a9c0-8df1feba42dd'

If conversion to hexadecimal fails, the original bytes are returned
"""

this_uuid: Union[bytes, uuid.UUID]

try:
this_uuid = uuid.UUID(bytes=guid)
except Exception as e:
logger.debug(f"Unable to convert bytes to UUID: {bytes} -- {str(e)}")
this_uuid = guid
return str(this_uuid)