Skip to content
This repository was archived by the owner on Aug 19, 2025. It is now read-only.
This repository was archived by the owner on Aug 19, 2025. It is now read-only.

fix documentation about low level transaction API usage #389

@andredias

Description

@andredias

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.

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