Skip to content

Commit 0e0045a

Browse files
authored
Merge pull request #223 fixed use transaction object when commit with flag
2 parents fc326d5 + f65c480 commit 0e0045a

File tree

5 files changed

+49
-4
lines changed

5 files changed

+49
-4
lines changed

Diff for: CHANGELOG.md

+2
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

Diff for: tests/aio/test_tx.py

+23-1
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,28 @@ 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(
127+
"INSERT INTO %s (id) VALUES (1)" % table_name, commit_tx=True
128+
)
129+
130+
with pytest.raises(RuntimeError):
131+
await tx.execute("INSERT INTO %s (id) VALUES (2)" % table_name)
132+
133+
await tx.commit()
134+
135+
async with s.transaction() as tx:
136+
rs = await tx.execute("SELECT COUNT(*) as cnt FROM %s" % table_name)
137+
assert rs[0].rows[0].cnt == 1
138+
139+
await pool.retry_operation(check_transaction)
140+
141+
120142
@pytest.mark.asyncio
121143
async def test_split_transactions_allow_split(driver, table_name):
122144
async with ydb.aio.SessionPool(driver, 1) as pool:

Diff for: tests/table/test_tx.py

+22-1
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,27 @@ 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(
120+
"INSERT INTO %s (id) VALUES (1)" % table_name, commit_tx=True
121+
)
122+
123+
with pytest.raises(RuntimeError):
124+
tx.execute("INSERT INTO %s (id) VALUES (2)" % table_name)
125+
126+
tx.commit()
127+
128+
with s.transaction() as tx:
129+
rs = tx.execute("SELECT COUNT(*) as cnt FROM %s" % table_name)
130+
assert rs[0].rows[0].cnt == 1
131+
132+
pool.retry_operation_sync(check_transaction)
133+
134+
114135
def test_split_transactions_allow_split(driver_sync, table_name):
115136
with ydb.SessionPool(driver_sync, 1) as pool:
116137

Diff for: ydb/aio/table.py

-2
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

Diff for: ydb/table.py

+2
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._COMMIT)
23192321

23202322
return self._driver(
23212323
_tx_ctx_impl.execute_request_factory(

0 commit comments

Comments
 (0)