Closed
Description
Please consider this script
import asyncio
import asyncpg
async def upload(data):
conn = await asyncpg.connect(database='t01')
async with conn.transaction():
await conn.executemany('insert into t (t) values ($1)', data)
loop = asyncio.get_event_loop()
data = ([v] for v in range(10))
loop.run_until_complete(upload(data))
If I change the data = ...
line to
data = ([x] for v in range(10))
I am getting
...
File "asyncpg/protocol/protocol.pyx", line 354, in asyncpg.protocol.protocol.BaseProtocol._ensure_clear_state (asyncpg/protocol/protocol.c:59044)
asyncpg.exceptions._base.InterfaceError: cannot perform operation: another operation is in progres
Keeping the erroneous data = ...
line and after commenting out the async with conn.transaction()
line, I am getting the following exception
File "asyncpg/protocol/protocol.pyx", line 181, in genexpr (asyncpg/protocol/protocol.c:55322)
File "test-script.py", line 11, in <genexpr>
data = ([x] for v in range(10))
NameError: name 'x' is not defined
When running within transaction, the exception should be exactly the same as running without a transaction - the exception shown on the last listing above.