Skip to content

Commit 008d331

Browse files
authored
Merge pull request #39 from ydb-platform/fix-issues-in-aio-library
fixes in ydb.aio library
2 parents d0dd847 + 840f3cf commit 008d331

File tree

5 files changed

+60
-6
lines changed

5 files changed

+60
-6
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.7.0 ##
2+
3+
* fixes in TxContext in ydb.aio module.
4+
15
## 2.6.0 ##
26

37
* support `with_native_interval_in_result_sets` flag in the table client.

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
setuptools.setup(
88
name="ydb",
9-
version="2.6.0",
9+
version="2.7.0",
1010
description="YDB Python SDK",
1111
author="Yandex LLC",
1212
author_email="[email protected]",

tests/aio/test_tx.py

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import pytest
2+
3+
4+
@pytest.mark.asyncio
5+
async def test_tx_commit(driver, database):
6+
session = await driver.table_client.session().create()
7+
prepared = await session.prepare(
8+
"DECLARE $param as Int32;\n SELECT $param as value",
9+
)
10+
11+
tx = session.transaction()
12+
await tx.execute(prepared, {"$param": 2})
13+
await tx.commit()
14+
await tx.commit()
15+
16+
17+
@pytest.mark.asyncio
18+
async def test_tx_rollback(driver, database):
19+
session = await driver.table_client.session().create()
20+
prepared = await session.prepare(
21+
"DECLARE $param as Int32;\n SELECT $param as value",
22+
)
23+
24+
tx = session.transaction()
25+
await tx.execute(prepared, {"$param": 2})
26+
await tx.rollback()
27+
await tx.rollback()
28+
29+
30+
@pytest.mark.asyncio
31+
async def test_tx_begin(driver, database):
32+
session = await driver.table_client.session().create()
33+
await session.create()
34+
35+
tx = session.transaction()
36+
await tx.begin()
37+
await tx.begin()
38+
await tx.rollback()

ydb/aio/table.py

+16-4
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ async def keep_alive(self, settings=None): # pylint: disable=W0236
5454
return await super().keep_alive(settings)
5555

5656
async def create(self, settings=None): # pylint: disable=W0236
57-
return await super().create(settings)
57+
res = super().create(settings)
58+
if asyncio.iscoroutine(res):
59+
res = await res
60+
return res
5861

5962
async def delete(self, settings=None): # pylint: disable=W0236
6063
return await super().delete(settings)
@@ -184,13 +187,22 @@ async def execute(
184187
return await super().execute(query, parameters, commit_tx, settings)
185188

186189
async def commit(self, settings=None): # pylint: disable=W0236
187-
return await super().commit(settings)
190+
res = super().commit(settings)
191+
if asyncio.iscoroutine(res):
192+
res = await res
193+
return res
188194

189195
async def rollback(self, settings=None): # pylint: disable=W0236
190-
return await super().rollback(settings)
196+
res = super().rollback(settings)
197+
if asyncio.iscoroutine(res):
198+
res = await res
199+
return res
191200

192201
async def begin(self, settings=None): # pylint: disable=W0236
193-
return await super().begin(settings)
202+
res = super().begin(settings)
203+
if asyncio.iscoroutine(res):
204+
res = await res
205+
return res
194206

195207

196208
async def retry_operation(

ydb/ydb_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION = "2.6.0"
1+
VERSION = "2.7.0"

0 commit comments

Comments
 (0)