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

fix documentation about low level transaction API usage #389

Closed
andredias opened this issue Sep 12, 2021 · 0 comments · Fixed by #390
Closed

fix documentation about low level transaction API usage #389

andredias opened this issue Sep 12, 2021 · 0 comments · Fixed by #390

Comments

@andredias
Copy link
Contributor

According to the encode/Databases documentation about Transactions, a common pattern for lower-level transaction API is:

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

However, calling await transaction.start() is a duplication and leads to error because it is implicitly invoked by await database.transaction(), as can be seen from this snippet of code.

So, the documentation should skip calling start:

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

In the chat room, @aminalaee pointed out it would be possible to use start too if the transaction instantiation wasn't awaited:

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

Although both forms are correct, keeping them both in the documentation will be confusing. I recommend that we keep the first one because it is simpler.

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

Successfully merging a pull request may close this issue.

1 participant