Skip to content

Commit a64c4bc

Browse files
committed
fixed use transaction object when commit with flag
1 parent fc326d5 commit a64c4bc

File tree

5 files changed

+45
-4
lines changed

5 files changed

+45
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
* fixed use transaction object when commit with flag
2+
13
## 2.13.2 ##
24
* fix snapshot attribute in class _ResultSet
35

tests/aio/test_tx.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ async def test_tx_snapshot_ro(driver, database):
9797

9898

9999
@pytest.mark.asyncio
100-
async def test_split_transactions_deny_split(driver, table_name):
100+
async def test_split_transactions_deny_split_explicit_commit(driver, table_name):
101101
async with ydb.aio.SessionPool(driver, 1) as pool:
102102

103103
async def check_transaction(s: ydb.aio.table.Session):
@@ -117,6 +117,26 @@ async def check_transaction(s: ydb.aio.table.Session):
117117
await pool.retry_operation(check_transaction)
118118

119119

120+
@pytest.mark.asyncio
121+
async def test_split_transactions_deny_split_flag_commit(driver, table_name):
122+
async with ydb.aio.SessionPool(driver, 1) as pool:
123+
124+
async def check_transaction(s: ydb.aio.table.Session):
125+
async with s.transaction(allow_split_transactions=False) as tx:
126+
await tx.execute("INSERT INTO %s (id) VALUES (1)" % table_name, commit_tx=True)
127+
128+
with pytest.raises(RuntimeError):
129+
await tx.execute("INSERT INTO %s (id) VALUES (2)" % table_name)
130+
131+
await tx.commit()
132+
133+
async with s.transaction() as tx:
134+
rs = await tx.execute("SELECT COUNT(*) as cnt FROM %s" % table_name)
135+
assert rs[0].rows[0].cnt == 1
136+
137+
await pool.retry_operation(check_transaction)
138+
139+
120140
@pytest.mark.asyncio
121141
async def test_split_transactions_allow_split(driver, table_name):
122142
async with ydb.aio.SessionPool(driver, 1) as pool:

tests/table/test_tx.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def test_tx_snapshot_ro(driver_sync, database):
9191
assert data[0].rows == [{"value": 2}]
9292

9393

94-
def test_split_transactions_deny_split(driver_sync, table_name):
94+
def test_split_transactions_deny_split_explicit_commit(driver_sync, table_name):
9595
with ydb.SessionPool(driver_sync, 1) as pool:
9696

9797
def check_transaction(s: ydb.table.Session):
@@ -111,6 +111,25 @@ def check_transaction(s: ydb.table.Session):
111111
pool.retry_operation_sync(check_transaction)
112112

113113

114+
def test_split_transactions_deny_split_flag_commit(driver_sync, table_name):
115+
with ydb.SessionPool(driver_sync, 1) as pool:
116+
117+
def check_transaction(s: ydb.table.Session):
118+
with s.transaction(allow_split_transactions=False) as tx:
119+
tx.execute("INSERT INTO %s (id) VALUES (1)" % table_name, commit_tx=True)
120+
121+
with pytest.raises(RuntimeError):
122+
tx.execute("INSERT INTO %s (id) VALUES (2)" % table_name)
123+
124+
tx.commit()
125+
126+
with s.transaction() as tx:
127+
rs = tx.execute("SELECT COUNT(*) as cnt FROM %s" % table_name)
128+
assert rs[0].rows[0].cnt == 1
129+
130+
pool.retry_operation_sync(check_transaction)
131+
132+
114133
def test_split_transactions_allow_split(driver_sync, table_name):
115134
with ydb.SessionPool(driver_sync, 1) as pool:
116135

ydb/aio/table.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,6 @@ async def execute(
194194
self, query, parameters=None, commit_tx=False, settings=None
195195
): # pylint: disable=W0236
196196

197-
self._check_split()
198-
199197
return await super().execute(query, parameters, commit_tx, settings)
200198

201199
async def commit(self, settings=None): # pylint: disable=W0236

ydb/table.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2316,6 +2316,8 @@ def execute(self, query, parameters=None, commit_tx=False, settings=None):
23162316
"""
23172317

23182318
self._check_split()
2319+
if commit_tx:
2320+
self._set_finish(self, self._COMMIT)
23192321

23202322
return self._driver(
23212323
_tx_ctx_impl.execute_request_factory(

0 commit comments

Comments
 (0)