Do you use a PostgreSQL SaaS? If so, which? Can you reproduce
the issue with a local PostgreSQL install?: No, I am not using PostgreSQL SaaS
Python version: 3.9.16
Platform: Fedora 36
Do you use pgbouncer?: No
Did you install asyncpg with pip?: Yes
If you built asyncpg locally, which version of Cython did you use?: No local build was done
Can the issue be reproduced under both asyncio and
uvloop?:
The following two test cases do exactly the same, but one of them uses a cursor and the other one doesn't:
async def test_cursor(postgresql_client: asyncpg.Connection):
async with postgresql_client.transaction():
await postgresql_client.execute("CREATE TABLE test(id INTEGER PRIMARY KEY)")
await postgresql_client.execute("INSERT INTO test VALUES(1)")
async for record in postgresql_client.cursor("SELECT * FROM test"):
print(record["id"])
await postgresql_client.execute("ALTER TABLE test ADD COLUMN test boolean")
async def test_no_cursor(postgresql_client: asyncpg.Connection):
async with postgresql_client.transaction():
await postgresql_client.execute("CREATE TABLE test(id INTEGER PRIMARY KEY)")
await postgresql_client.execute("INSERT INTO test VALUES(1)")
records = await postgresql_client.fetch("SELECT * FROM test")
for record in records:
print(record["id"])
await postgresql_client.execute("ALTER TABLE test ADD COLUMN test boolean")
Observed behavior
The behavior I observe is that the test_no_cursor test case works as expected without any failure. The test_cursor test case on the other hand fails with the following error:
asyncpg.exceptions.ObjectInUseError: cannot ALTER TABLE "test" because it is being used by active queries in this session.
Expected behavior
I would expect that both tests cases succeed and behave identically. I have been following this documentation page on how to use cursors.
The following two test cases do exactly the same, but one of them uses a cursor and the other one doesn't:
Observed behavior
The behavior I observe is that the
test_no_cursor
test case works as expected without any failure. Thetest_cursor
test case on the other hand fails with the following error:Expected behavior
I would expect that both tests cases succeed and behave identically. I have been following this documentation page on how to use cursors.