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

Warn for open transactions when a connection is garbage collected #554

Open
zevisert opened this issue May 26, 2023 · 0 comments
Open

Warn for open transactions when a connection is garbage collected #554

zevisert opened this issue May 26, 2023 · 0 comments
Labels
clean up Refinement to existing functionality

Comments

@zevisert
Copy link
Contributor

zevisert commented May 26, 2023

Originally posted by @zevisert in #546 (comment)

Scenarios where a transaction instance is deleted without calling .commit() or .rollback() (perhaps because a database or connection is being garbage collected) are possible if users are using the documented low-level transaction management API, and they didn't set up their try/except/else logic correctly.

# MVE that hangs on master, 0.7.0, 0.6.2, 0.5.5, 0.4.3, 0.3.2, 0.2.6, 0.1.12 
import databases, asyncio, os

async def mve():
    async with databases.Database(os.environ['TEST_DATABASE_URL']) as db:
        transaction = db.transaction()
        await transaction.start()

asyncio.run(mve())

I consider this user-error, but it also makes sense that this hangs on shutdown. From the database driver's perspective, there is an open transaction that has not executed a COMMIT or ROLLBACK statement, better wait for that to happen before shutting down.

The best thing databases could do here is to emit a warning if __del__ (?) is called on a connection with entries that remain in it's ._transaction_stack. Maybe even each of those transactions could have a .rollback() applied to them.

@zanieb zanieb added the clean up Refinement to existing functionality label Jul 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clean up Refinement to existing functionality
Projects
None yet
Development

No branches or pull requests

2 participants