Skip to content

Commit ea3e445

Browse files
committed
fix cursor commit
1 parent 7882dbf commit ea3e445

File tree

5 files changed

+14
-22
lines changed

5 files changed

+14
-22
lines changed

asyncodbc/connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def __init__(
122122
def _execute(self, func, *args, **kwargs):
123123
# execute function with args and kwargs in thread pool
124124
func = partial(func, *args, **kwargs)
125-
future = asyncio.get_running_loop().run_in_executor(self._executor, func)
125+
future = asyncio.get_event_loop().run_in_executor(self._executor, func)
126126
return future
127127

128128
async def _connect(self):

asyncodbc/cursor.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,4 +337,3 @@ async def __aenter__(self):
337337

338338
async def __aexit__(self, exc_type, exc_val, exc_tb):
339339
await self.close()
340-
return

asyncodbc/utils.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,6 @@ async def __aenter__(self):
7878
return self._obj
7979

8080
async def __aexit__(self, exc_type, exc, tb):
81-
if exc_type:
82-
await self._obj.rollback()
83-
elif not self._obj.autocommit:
84-
await self._obj.commit()
8581
await self._obj.close()
8682
self._obj = None
8783

@@ -116,8 +112,5 @@ async def __aexit__(self, exc_type, exc, tb):
116112

117113
class _ConnectionContextManager(_ContextManager):
118114
async def __aexit__(self, exc_type, exc, tb):
119-
if exc_type is not None:
120-
self._obj.close()
121-
else:
122-
await self._obj.close()
115+
await self._obj.close()
123116
self._obj = None

conftest.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,15 @@ def event_loop():
2525
@pytest_asyncio.fixture(scope="session", autouse=True)
2626
async def database():
2727
connection = await asyncodbc.connect(dsn=os.getenv("TEST_DSN"), autocommit=True)
28-
cur = await connection.cursor()
2928
db = f"test_{uuid.uuid4()}".replace("-", "")
30-
await cur.execute(f"CREATE DATABASE {db};")
29+
await connection.execute(f"CREATE DATABASE {db};")
3130
yield db
32-
await cur.execute(f"DROP DATABASE {db};")
31+
await connection.execute(f"DROP DATABASE {db};")
3332
await connection.close()
3433

3534

3635
@pytest.fixture
37-
async def connection_maker(dsn):
36+
async def connection_maker(dsn, database):
3837
cleanup = []
3938

4039
async def make(**kw):
@@ -44,7 +43,7 @@ async def make(**kw):
4443
else:
4544
executor = kw["executor"]
4645

47-
conn = await asyncodbc.connect(dsn=dsn, **kw)
46+
conn = await asyncodbc.connect(dsn=dsn, database=database, **kw)
4847
cleanup.append((conn, executor))
4948
return conn
5049

tests/test_pool.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ async def wait_closed():
352352
do_release(c1),
353353
do_release(c2),
354354
)
355-
assert ["release", "release", "wait_closed"] == ops
355+
assert sorted(["release", "release", "wait_closed"]) == sorted(ops)
356356
assert 0 == pool.freesize
357357

358358

@@ -466,28 +466,29 @@ async def aexit_conntex_managet(conn):
466466
# commit on exit if no error
467467
params = (1, "123.45")
468468
async with conn.cursor() as cur:
469-
await cur.execute("CREATE TABLE cmt1(n int, v VARCHAR(10))")
470-
await cur.execute("INSERT INTO cmt1 VALUES (?,?);", params)
469+
await cur.execute("CREATE TABLE cmt(n int, v VARCHAR(10))")
470+
await cur.execute("INSERT INTO cmt VALUES (?,?)", params)
471471
async with conn.cursor() as cur:
472-
await cur.execute("SELECT v FROM cmt1 WHERE n=1;")
472+
await cur.execute("SELECT v FROM cmt WHERE n=1;")
473473
(value,) = await cur.fetchone()
474474
assert value == params[1]
475475

476476
# rollback on exit if error
477477
with pytest.raises(Error):
478478
async with conn.cursor() as cur:
479-
await cur.execute("ins INTO cmt1 VALUES (2, '666');")
479+
await cur.execute("ins INTO cmt VALUES (2, '666');")
480480
async with conn.cursor() as cur:
481-
await cur.execute("SELECT v FROM cmt1 WHERE n=2;")
481+
await cur.execute("SELECT v FROM cmt WHERE n=2")
482482
row = await cur.fetchone()
483483
assert row is None
484484

485485
async with conn.cursor() as cur:
486-
await cur.execute("DROP TABLE cmt1;")
486+
await cur.execute("DROP TABLE cmt")
487487

488488
conn = await connection_maker(autocommit=False)
489489
assert not conn.autocommit
490490
await aexit_conntex_managet(conn)
491+
await conn.commit()
491492

492493
conn = await connection_maker(autocommit=True)
493494
assert conn.autocommit

0 commit comments

Comments
 (0)