Skip to content

Commit f01b07a

Browse files
Correct handling of XID binary components in thin mode.
1 parent 0e3bae4 commit f01b07a

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

src/oracledb/impl/thin/messages.pyx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2528,14 +2528,12 @@ cdef class TransactionChangeStateMessage(Message):
25282528
# acquire data to send to the server
25292529
if self.xid is not None:
25302530
format_id = self.xid[0]
2531-
if isinstance(self.xid[1], bytes):
2532-
global_transaction_id = self.xid[1]
2533-
else:
2534-
global_transaction_id = self.xid[1].encode()
2535-
if isinstance(self.xid[2], bytes):
2536-
branch_qualifier = self.xid[2]
2537-
else:
2538-
branch_qualifier = self.xid[2].encode()
2531+
global_transaction_id = self.xid[1] \
2532+
if isinstance(self.xid[1], bytes) \
2533+
else self.xid[1].encode()
2534+
branch_qualifier = self.xid[2] \
2535+
if isinstance(self.xid[2], bytes) \
2536+
else self.xid[2].encode()
25392537
xid_bytes = global_transaction_id + branch_qualifier
25402538
xid_bytes += bytes(128 - len(xid_bytes))
25412539

@@ -2609,8 +2607,12 @@ cdef class TransactionSwitchMessage(Message):
26092607
# acquire data to send to the server
26102608
if self.xid is not None:
26112609
format_id = self.xid[0]
2612-
global_transaction_id = self.xid[1].encode()
2613-
branch_qualifier = self.xid[2].encode()
2610+
global_transaction_id = self.xid[1] \
2611+
if isinstance(self.xid[1], bytes) \
2612+
else self.xid[1].encode()
2613+
branch_qualifier = self.xid[2] \
2614+
if isinstance(self.xid[2], bytes) \
2615+
else self.xid[2].encode()
26142616
xid_bytes = global_transaction_id + branch_qualifier
26152617
xid_bytes += bytes(128 - len(xid_bytes))
26162618
if self.conn_impl._internal_name is not None:

tests/test_4400_tpc.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class TestCase(test_env.BaseTestCase):
3434
def test_4400(self):
3535
"4400 - test begin, prepare, roll back global transaction"
3636
self.cursor.execute("truncate table TestTempTable")
37-
xid = self.conn.xid(3900, "txn3900", "branchId")
37+
xid = self.conn.xid(3900, b"txn3900", b"branchId")
3838
self.conn.tpc_begin(xid)
3939
self.assertEqual(self.conn.tpc_prepare(), False)
4040
self.conn.tpc_begin(xid)
@@ -70,7 +70,7 @@ def test_4402(self):
7070
"4402 - test multiple global transactions on the same connection"
7171
self.cursor.execute("truncate table TestTempTable")
7272
xid1 = self.conn.xid(3902, "txn3902", "branch1")
73-
xid2 = self.conn.xid(3902, "txn3902", "branch2")
73+
xid2 = self.conn.xid(3902, b"txn3902", b"branch2")
7474
self.conn.tpc_begin(xid1)
7575
self.cursor.execute(
7676
"""
@@ -102,7 +102,7 @@ def test_4402(self):
102102
def test_4403(self):
103103
"4403 - test rollback with parameter xid"
104104
self.cursor.execute("truncate table TestTempTable")
105-
xid1 = self.conn.xid(3901, "txn3901", "branch1")
105+
xid1 = self.conn.xid(3901, b"txn3901", b"branch1")
106106
xid2 = self.conn.xid(3902, "txn3902", "branch2")
107107
for count, xid in enumerate([xid1, xid2]):
108108
self.conn.tpc_begin(xid)
@@ -170,7 +170,7 @@ def test_4406(self):
170170
"4406 - test ending a transaction with parameter xid"
171171
self.cursor.execute("truncate table TestTempTable")
172172
xid1 = self.conn.xid(4406, "txn4406a", "branch3")
173-
xid2 = self.conn.xid(4406, "txn4406b", "branch4")
173+
xid2 = self.conn.xid(4406, b"txn4406b", b"branch4")
174174
self.conn.tpc_begin(xid1)
175175
self.cursor.execute(
176176
"""

0 commit comments

Comments
 (0)