Skip to content

Commit bf7756a

Browse files
Corrected two-phase commit support for asyncio in addition to the
regular synchronous coding pattern.
1 parent 092c4eb commit bf7756a

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

src/oracledb/connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1787,7 +1787,6 @@ async def tpc_recover(self) -> list:
17871787
DBA_PENDING_TRANSACTIONS.
17881788
"""
17891789
with self.cursor() as cursor:
1790-
cursor.rowfactory = Xid
17911790
await cursor.execute(
17921791
"""
17931792
select
@@ -1796,6 +1795,7 @@ async def tpc_recover(self) -> list:
17961795
branchid
17971796
from dba_pending_transactions"""
17981797
)
1798+
cursor.rowfactory = Xid
17991799
return await cursor.fetchall()
18001800

18011801
async def tpc_rollback(self, xid: Xid = None) -> None:

tests/test_7400_tpc_async.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class TestCase(test_env.BaseAsyncTestCase):
3939
async def test_7400(self):
4040
"7400 - test begin, prepare, roll back global transaction"
4141
await self.cursor.execute("truncate table TestTempTable")
42-
xid = self.conn.xid(3900, "txn3900", "branchId")
42+
xid = self.conn.xid(3900, b"txn3900", b"branchId")
4343
await self.conn.tpc_begin(xid)
4444
self.assertEqual(await self.conn.tpc_prepare(), False)
4545
await self.conn.tpc_begin(xid)
@@ -77,7 +77,7 @@ async def test_7402(self):
7777
"7402 - test multiple global transactions on the same connection"
7878
await self.cursor.execute("truncate table TestTempTable")
7979
xid1 = self.conn.xid(3902, "txn3902", "branch1")
80-
xid2 = self.conn.xid(3902, "txn3902", "branch2")
80+
xid2 = self.conn.xid(3902, b"txn3902", b"branch2")
8181
await self.conn.tpc_begin(xid1)
8282
await self.cursor.execute(
8383
"""
@@ -109,7 +109,7 @@ async def test_7402(self):
109109
async def test_7403(self):
110110
"7403 - test rollback with parameter xid"
111111
await self.cursor.execute("truncate table TestTempTable")
112-
xid1 = self.conn.xid(3901, "txn3901", "branch1")
112+
xid1 = self.conn.xid(3901, b"txn3901", b"branch1")
113113
xid2 = self.conn.xid(3902, "txn3902", "branch2")
114114
for count, xid in enumerate([xid1, xid2]):
115115
await self.conn.tpc_begin(xid)
@@ -181,7 +181,7 @@ async def test_7406(self):
181181
"7406 - test ending a transaction with parameter xid"
182182
await self.cursor.execute("truncate table TestTempTable")
183183
xid1 = self.conn.xid(7406, "txn7406a", "branch3")
184-
xid2 = self.conn.xid(7406, "txn7406b", "branch4")
184+
xid2 = self.conn.xid(7406, b"txn7406b", b"branch4")
185185
await self.conn.tpc_begin(xid1)
186186
await self.cursor.execute(
187187
"""
@@ -225,15 +225,13 @@ async def test_7407(self):
225225
await self.cursor.execute("select * from DBA_PENDING_TRANSACTIONS")
226226
self.assertEqual(await self.cursor.fetchall(), recovers)
227227

228-
for format_id, txn, branch in recovers:
229-
if format_id % 2 == 0:
230-
xid = self.conn.xid(format_id, txn, branch)
228+
for xid in recovers:
229+
if xid.format_id % 2 == 0:
231230
await self.conn.tpc_commit(xid)
232231
recovers = await self.conn.tpc_recover()
233232
self.assertEqual(len(recovers), n_xids // 2)
234233

235-
for format_id, txn, branch in recovers:
236-
xid = self.conn.xid(format_id, txn, branch)
234+
for xid in recovers:
237235
await self.conn.tpc_rollback(xid)
238236
recovers = await self.conn.tpc_recover()
239237
self.assertEqual(len(recovers), 0)

utils/templates/connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1583,7 +1583,6 @@ async def tpc_recover(self) -> list:
15831583
DBA_PENDING_TRANSACTIONS.
15841584
"""
15851585
with self.cursor() as cursor:
1586-
cursor.rowfactory = Xid
15871586
await cursor.execute(
15881587
"""
15891588
select
@@ -1592,6 +1591,7 @@ async def tpc_recover(self) -> list:
15921591
branchid
15931592
from dba_pending_transactions"""
15941593
)
1594+
cursor.rowfactory = Xid
15951595
return await cursor.fetchall()
15961596

15971597
async def tpc_rollback(self, xid: Xid = None) -> None:

0 commit comments

Comments
 (0)