fix: исправить RuntimeError в aiosqlite — _get_conn как async context manager

`async with await _get_conn()` запускал тред дважды: первый раз внутри
`_get_conn` через `await aiosqlite.connect()`, второй раз в `__aenter__`
через `await self`. Преобразован в `@asynccontextmanager` с `yield` и
`finally: conn.close()`. Все вызывающие места обновлены. Тест
`test_init_db_synchronous` обновлён под новый API.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Gros Frumos 2026-03-20 23:16:12 +02:00
parent 1c383191cc
commit 7db8b849e0
2 changed files with 16 additions and 12 deletions

View file

@ -109,10 +109,9 @@ async def test_init_db_synchronous():
await db.init_db()
# Check synchronous on a new connection via _get_conn()
from backend.db import _get_conn
conn = await _get_conn()
async with conn.execute("PRAGMA synchronous") as cur:
row = await cur.fetchone()
await conn.close()
async with _get_conn() as conn:
async with conn.execute("PRAGMA synchronous") as cur:
row = await cur.fetchone()
# 1 == NORMAL
assert row[0] == 1
finally: