@@ -532,24 +532,29 @@ def _check_command_not_in_error_or_closed_state(
532532 raise ServerOperationError (
533533 get_operations_resp .displayMessage ,
534534 {
535- "operation-id" : op_handle and op_handle .operationId .guid ,
535+ "operation-id" : op_handle
536+ and self .guid_to_hex_id (op_handle .operationId .guid ),
536537 "diagnostic-info" : get_operations_resp .diagnosticInfo ,
537538 },
538539 )
539540 else :
540541 raise ServerOperationError (
541542 get_operations_resp .errorMessage ,
542543 {
543- "operation-id" : op_handle and op_handle .operationId .guid ,
544+ "operation-id" : op_handle
545+ and self .guid_to_hex_id (op_handle .operationId .guid ),
544546 "diagnostic-info" : None ,
545547 },
546548 )
547549 elif get_operations_resp .operationState == ttypes .TOperationState .CLOSED_STATE :
548550 raise DatabaseError (
549551 "Command {} unexpectedly closed server side" .format (
550- op_handle and op_handle .operationId .guid
552+ op_handle and self . guid_to_hex_id ( op_handle .operationId .guid )
551553 ),
552- {"operation-id" : op_handle and op_handle .operationId .guid },
554+ {
555+ "operation-id" : op_handle
556+ and self .guid_to_hex_id (op_handle .operationId .guid )
557+ },
553558 )
554559
555560 def _poll_for_status (self , op_handle ):
@@ -942,7 +947,11 @@ def close_command(self, op_handle):
942947 return resp .status
943948
944949 def cancel_command (self , active_op_handle ):
945- logger .debug ("Cancelling command {}" .format (active_op_handle .operationId .guid ))
950+ logger .debug (
951+ "Cancelling command {}" .format (
952+ self .guid_to_hex_id (active_op_handle .operationId .guid )
953+ )
954+ )
946955 req = ttypes .TCancelOperationReq (active_op_handle )
947956 self .make_request (self ._client .CancelOperation , req )
948957
@@ -954,3 +963,23 @@ def handle_to_id(session_handle):
954963 def handle_to_hex_id (session_handle : TCLIService .TSessionHandle ):
955964 this_uuid = uuid .UUID (bytes = session_handle .sessionId .guid )
956965 return str (this_uuid )
966+
967+ @staticmethod
968+ def guid_to_hex_id (guid : bytes ) -> str :
969+ """Return a hexadecimal string instead of bytes
970+
971+ Example:
972+ IN b'\x01 \xee \x1d )\xa4 \x19 \x1d \xb6 \xa9 \xc0 \x8d \xf1 \xfe \xba B\xdd '
973+ OUT '01ee1d29-a419-1db6-a9c0-8df1feba42dd'
974+
975+ If conversion to hexadecimal fails, the original bytes are returned
976+ """
977+
978+ this_uuid : Union [bytes , uuid .UUID ]
979+
980+ try :
981+ this_uuid = uuid .UUID (bytes = guid )
982+ except Exception as e :
983+ logger .debug (f"Unable to convert bytes to UUID: { bytes } -- { str (e )} " )
984+ this_uuid = guid
985+ return str (this_uuid )
0 commit comments