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.

Assertion error when using transaction decorator #123

Description

@SebasAren

I'm using fastapi in combination with this library but when I use the transaction decorator I'm sporadically getting the following assertion error:

File ".../lib/python3.7/site-packages/databases/core.py", line 305, in commit
    assert self._connection._transaction_stack[-1] is self

I'm using a pretty basic fastapi setup making use of the on event startup hook to connect the database. The database is mysql, which i'm connecting to with the aiomysql package (and this library).

I've decorated all of my routes in the following manner :

@app.get("/", response_model=DataModel)
@database.transaction()
async def hello_world(q: str):
    query = sqlalchemy.select(table)
    result = await database.fetch_all(query)
    return result

This works most of the time, but once in a while it raises the above exception. If I remove the transaction decorator everything works as expected.

Why do I get this error? Am I using the decorator improperly?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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