drizzle-team / drizzle-orm

Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅
https://orm.drizzle.team
Apache License 2.0
21.57k stars 490 forks source link

[BUG]: Async SQLite transaction will not rollback #1472

Open nonua opened 8 months ago

nonua commented 8 months ago

What version of drizzle-orm are you using?

0.28.6

What version of drizzle-kit are you using?

0.19.13

Describe the Bug

When using a synchronous sqlite driver with transactions, only a synchronous callback would apply the rollback.

Example:


// rollback will not undo the delete because of async callback
db.transaction(async (tx) => {
   tx.delete(example).where(eq(example.id, exampleId)).run();
   tx.rollback();
})

// rollback will undo
db.transaction((tx) => {
   tx.delete(example).where(eq(example.id, exampleId)).run();
   tx.rollback();
})

this was particularly difficult to debug because the docs describe that this is a valid syntax for any driver (or rather does not specify a difference).

Expected behavior

Either:

Trugamr commented 7 months ago

Running into same issue using sqlite.

icflorescu commented 6 months ago

Running into a similar issue: I just noticed that async transactions aren't automatically rolled back on error, which would be the expected behavior 🥹

gabrielgrover commented 4 months ago

This is definitely an issue. https://github.com/drizzle-team/drizzle-orm/issues/1723#issuecomment-1947752593

cobbvanth commented 3 hours ago

This is a major issue that really needs to be fixed...