asyncpg: Awaiting multiple `execute` within a transaction seems to block forever
I’m trying to execute a couple of sql queries with arguments, in a context of a transaction.
I used this code:
async def execute_many_in_transaction(self, queries_and_args):
pool = await get_pool() # returns a pool of clients
async with pool.acquire() as connection:
async with connection.transaction():
for query, args in queries_and_args:
await connection.execute(
query, *args
)
When I call it with a list with one tuple [("SQL STATEMENT", [arg1, arg2])]
all is good.
The moment I try to execute more than one, it just hangs there forever. For example:
[
("SQL STATEMENT 1", [arg1, arg2]),
("SQL STATEMENT 2", [arg1, arg3]),
]
I know that there is execute_many
method, but that only seems to work on the same sql statement with multiple lists of arguments.
Is there something I’m misunderstanding ?
Thanks !
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 22 (10 by maintainers)
Be nice if folks elaborate a bit more on what the “other” problem was that caused this issue in the first place.
Amazingly, it turns out that the query wasn’t hanging forever… It was hanging for a couple of minutes.
When we dug down to see what
postgres
was actually executing, it turned out that it transformed any simple query taking into account a custom enum into a super complex monster, despite the fact, that the exact query ent throughpsql
was straightforwards. Will continue to investigate.