tortoise/tortoise-orm

Problems using `.raw()` instead of `.filter()`

davidmcnabnz opened this issue · 1 comments

Describe the bug
To get consistency between Tortoise-based and non-Tortoise based queries, I started replacing the usual <ModelClassName>.filter(...) fetches with <ModelClassName>.raw(<PlainSQLQueryString>).

It seemed to work, but I later found that saves were often not actually committing to the database. This caused some serious data consistency and workflow problems in several of my networks, which only came right after changing back to .filter(...).

Expected behavior
When using <ModelClassName>.raw(...) I was expecting the returned Model row objects to behave in the same way as the ones returned from awaiting a <ModelClassName>.filter(...) query.

Additional context
Is there a "safe" and recommended way to get Model row objects from raw SQL queries, which behave identically to those retrieved from .filter(...) ?

All help appreciated.

It seemed to work, but I later found that saves were often not actually committing to the database.

Hmm...What does that mean? Can you provide an example of how it works as you expect?