aio-libs / aio-libs/aiomysql

OperationalError during ROLLBACK or COMMIT deadlocks entire sa engine

未關閉
#353 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
bug sqlalchemy
主要語言
Python
星號
1.9k
分支
272
PR 合併指標
30 天內沒有已合併 PR

描述

Didn't dive deeper, because in my case it is enough to just set autocommit=True and get rid of all transactions, but here is a minimal test reproducing a problem (v0.0.19), at least giving very similar results:

``` python
engine = await create_engine(
...
autocommit=False,
)

async def test_mysql_connection_error():
used = engine._pool._used
assert len(used) == 0

with pytest.raises(aiomysql.OperationalError):
with mock.patch('aiomysql.sa.connection.SAConnection.execute',
side_effect=aiomysql.OperationalError):
with mock.patch('aiomysql.sa.transaction.Transaction.rollback',
side_effect=aiomysql.OperationalError):
async with engine.acquire() as conn: # type: SAConnection
async with conn.begin():
qs = table.select()
await conn.execute(qs)

used = mysql.engine._pool._used
assert len(used) == 0

async def test_mysql_connection_error2():
used = mysql.engine._pool._used
assert len(used) == 0

with pytest.raises(aiomysql.OperationalError):
with mock.patch('aiomysql.sa.transaction.Transaction.commit',
side_effect=aiomysql.OperationalError):
async with engine.acquire() as conn: # type: SAConnection
async with conn.begin():
qs = table.select()
await conn.execute(qs)

used = mysql.engine._pool._used
assert len(used) == 0
```

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。