databases icon indicating copy to clipboard operation
databases copied to clipboard

aiopg engine raises ResourceWarning in transactions

Open nkoshell opened this issue 5 years ago • 3 comments

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 avatar May 20 '20 10:05 nkoshell

@nkoshell did you find any solution to fix it? I have the same problem, and with asyncpg everything works fine.

kamilglod avatar Jan 16 '21 14:01 kamilglod

@nkoshell did you find any solution to fix it? I have the same problem, and with asyncpg everything works fine.

No. I use asyncpg instead of aiopg

nkoshell avatar Jan 16 '21 14:01 nkoshell

any news on that? I'm unable to switch from aiopg to asyncpg because pg_bouncer

felipecwb avatar Mar 16 '21 16:03 felipecwb