You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 text was updated successfully, but these errors were encountered:
When iterating on a cursor, make sure to close the portal once iteration
is done. This prevents the cursor from holding onto resources until the
end of transaction.
Fixes: #1008
When iterating on a cursor, make sure to close the portal once iteration
is done. This prevents the cursor from holding onto resources until the
end of transaction.
Fixes: #1008
the issue with a local PostgreSQL install?: No, I am not using PostgreSQL SaaS
uvloop?:
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.
The text was updated successfully, but these errors were encountered: