tortoise-orm: Error: Resetting connection with an active transaction

Describe the bug Every time I access the database, by create, get, save I get this error that spams my terminal and another side effect is that the data that’s returned becomes None, or when I try to save data it says saved but actually isn’t.

To Reproduce I’m not even sure, this just started happening randomly and I don’t know how to diagnose

Expected behavior What should happen is that my data is returned as normal AND when saving my data is actually saved, and also my terminal isn’t spammed 24/7 :c

Additional context None that comes to mind

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 20 (4 by maintainers)

Most upvoted comments

I have exactly the same problem, the data in bulk_create is not saved when this resetting connection message appears.

@atomic()
async def task():
    objects = [Customers(**customer) for customer in data]

    await Customers.bulk_create(
        objects,
        on_conflict=['customer_id'],
        ignore_conflicts=True,
        batch_size=1000
    )

try:
    await task()
except Exception as e:
    print(e)

I removed the atomic decorator and all transaction contexts from my application. I think it solved it. I could also be doing something wrong.

Python 3.10.12 pip 22.0.2

tortoise-orm 0.20.0 asyncpg 0.28.0 fastapi 0.103.2