Skip to content

Table being used by active queries in this session #1008

Closed
@arnaudsjs

Description

@arnaudsjs
  • asyncpg version: 0.27.0
  • PostgreSQL version: 13.6
  • 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions