Skip to content

Expose method on Connection object to determine if inside transaction #296

Closed
@bcaudell95

Description

@bcaudell95

Inside code using Connection objects to issue queries, it would be nice to assert that the Connection is inside a transaction. This allows production code using the library to nicely separate the code handling the fetching of Connections from the code issuing queries while still allowing the latter to make assertions about the context it's in.

Looking at the code, there is a member variable _top_xact which is None if not inside a transaction block, and which is set to the Transaction object otherwise. Thus, it appears to me that simply checking the value of this variable is sufficient for this method. Correct me if I'm missing anything.

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