Skip to content

"Another operation is in progress" error when using transactions and asyncio.gather #313

Closed
@jekel

Description

@jekel

Hello!
When i need to make several operations in parallel with db i'm using asyncio.gather with task and transaction inside it, but i have found that in GINO it does not work correctly - throws an error
asyncpg.exceptions._base.InterfaceError: cannot perform operation: another operation is in progress

How to reproduce it:

    async def t():
        async with db.transaction():
            await Model.query.gino.first()

    await asyncio.gather(*[t() for i in range(5)])

If i will place db.acquire before db.transaction it does not change anything.

I think that problem is that there must be new real connection and transaction in it when using asyncio.gather

stacktrace

 await Model.query.gino.first()
  File "venv/project/lib/python3.7/site-packages/gino/api.py", line 135, in first
    **params)
  File "venv/project/lib/python3.7/site-packages/gino/engine.py", line 681, in first
    return await conn.first(clause, *multiparams, **params)
  File "venv/project/lib/python3.7/site-packages/gino/engine.py", line 336, in first
    return await result.execute(one=True)
  File "venv/project/lib/python3.7/site-packages/gino/dialects/base.py", line 207, in execute
    context.statement, context.timeout, args, 1 if one else 0)
  File "venv/project/lib/python3.7/site-packages/gino/dialects/asyncpg.py", line 175, in async_execute
    query, executor, timeout)
  File "venv/project/lib/python3.7/site-packages/asyncpg/connection.py", line 1400, in _do_execute
    stmt = await self._get_statement(query, None)
  File "venv/project/lib/python3.7/site-packages/asyncpg/connection.py", line 323, in _get_statement
    statement = await self._protocol.prepare(stmt_name, query, timeout)
  File "asyncpg/protocol/protocol.pyx", line 165, in prepare
  File "asyncpg/protocol/protocol.pyx", line 675, in asyncpg.protocol.protocol.BaseProtocol._check_state
asyncpg.exceptions._base.InterfaceError: cannot perform operation: another operation is in progress
  • GINO version: 0.7.5
  • Python version: 3.7.0
  • asyncpg version: 0.17.0
  • PostgreSQL version: 9.6.9
  • Quart version 0.6.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugDescribes a bug in the system.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions