databases
databases copied to clipboard
aiopg engine raises ResourceWarning in transactions
Step to reproduce:
Python 3.7.7
import asyncio
from databases import Database
url = "postgresql+aiopg://localhost:5432"
async def generate_series(db, *args):
async with db.connection() as conn:
async for row in conn.iterate( # implicitly starts transaction
f"select generate_series({', '.join(f'{a}' for a in args)}) as i"
):
yield row["i"]
async def main():
async with Database(url) as db:
print([i async for i in generate_series(db, 1, 10)])
async with db.transaction():
print(await db.fetch_val("select 1"))
asyncio.run(main())
Result:
.../python3.7/site-packages/aiopg/connection.py:256: ResourceWarning: You can only have one cursor per connection. The cursor for connection will be closed forcibly <aiopg.connection::Connection isexecuting=False, closed=False, echo=False, cursor=<aiopg.cursor::Cursor name=None, closed=False>>. ' {!r}.').format(self), ResourceWarning)
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
.../python3.7/site-packages/aiopg/connection.py:256: ResourceWarning: You can only have one cursor per connection. The cursor for connection will be closed forcibly <aiopg.connection::Connection isexecuting=False, closed=False, echo=False, cursor=<aiopg.cursor::Cursor name=None, closed=False>>. ' {!r}.').format(self), ResourceWarning)
1
@nkoshell did you find any solution to fix it? I have the same problem, and with asyncpg everything works fine.
@nkoshell did you find any solution to fix it? I have the same problem, and with
asyncpgeverything works fine.
No. I use asyncpg instead of aiopg
any news on that?
I'm unable to switch from aiopg to asyncpg because pg_bouncer