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

Is it true that the "await transaction.start()" line is missing from the databases lower-level transaction API usage example? #596

Open
allyotov opened this issue Dec 10, 2024 · 1 comment

Comments

@allyotov
Copy link

The database help suggests the following way to use the low-level transaction API:

transaction = await database.transaction()
try:
    ...
except:
    await transaction.rollback()
else:
    await transaction.commit()

But if I try to use this code as is, I guess, the created transaction is not started. So, maybe, we have to start it explicitly as follows?

transaction = await database.transaction()
await transaction.start()  # start transaction explicitly
try:
    ...
except:
    await transaction.rollback()
else:
    await transaction.commit()

Please confirm or deny my assumption.

@allyotov
Copy link
Author

I think, my assumption is wrong, because if I run transaction.start() it doubles in connection's transaction stack, so when I will commit it, one instance of it will still be there in transaction stack, and that may cause further problems.

So the example in databases documentation is correct.

Thank you.

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