Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PostgreSQL: Transaction rollback errors with "another operation is in progress" #340

Open
rafalp opened this issue May 16, 2021 · 0 comments

Comments

@rafalp
Copy link
Member

rafalp commented May 16, 2021

I've noticed that if one of my tests fails, every next test will fail with error from async with database claiming that connection is still on.

Upon closer look I've found out that first tests failure triggers transaction's rollback which sends rollback to the database.

However asyncpg.exceptions._base.InterfaceError: cannot perform operation: another operation is in progress will be raised in response to this, resulting in invalid state:

is_connected = True
_transaction_stack = []

This state can't be fixed other by monkeypatching connection object, as trying to call disconnect() will try to pop item from empty _transaction_stack, causing other exception.

Min repro:

database = Database(url="...", force_rollback=True)

async with database:
    await raise_exception()

async with database:  # this will crash because previous database connection was not cleaned up completely.
   database.exec("...")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant