Description
Raphael ‘kena’ Poss (knz) commented:
A customer came to us with the following story (paraphrased)
I copy-pasted your example Python code, and then added
async
andawait
clauses in various places. For example:
async def transfer_funds(conn: Connection, frm, to, amount): async with conn.transaction(): # Check the current balance. from_balance = await conn.fetchval("SELECT balance FROM accounts WHERE id = '{}'".format(frm)) if from_balance < amount: err_msg = "Insufficient funds in account {}: have {}, need {}".format(frm, from_balance, amount) raise RuntimeError(err_msg) # Perform the transfer. await conn.execute("UPDATE accounts SET balance = balance - {} WHERE id = '{}'".format( amount, frm)) await conn.execute("UPDATE accounts SET balance = balance + {} WHERE id = '{}'".format( amount, to))
The resulting code "does not work" and CockroachDB complains with unimplemented: multiple active portals not supported
I advised the customer that their addition of async/await is causing their Python to issue multiple concurrent statements on the same connection object, which nternally uses multiple concurrent portals, which are not supported in crdb.
However this is not easy to understand, and we do not warn for it inside our tutorials.
I think our Python tutorials should cover uses of async/await and provide an example that works with it.
Jira Issue: DOC-535