drizzle-team / drizzle-team/drizzle-orm
[BUG]: Transactions rollback doesn't work
- Dominant language
- TypeScript
- Stars
- 35.8k
- Forks
- 1.6k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 4
Description
### What version of `drizzle-orm` are you using?
0.29.2
### What version of `drizzle-kit` are you using?
0.20.9
### Describe the Bug
I wrote a pretty simple transaction but when the error appears rollback doesn't work.
I have 3 steps and when the error happens on the second step, the first change is still in DB.
### Expected behavior
I expect that if the error happens at some point in the transaction the entire transaction rolls back. But it doesn't.
Even when I try to run rolling back manually I get an error: `[DrizzleError: Rollback] { name: 'DrizzleError', cause: undefined }`
### Environment & setup
It is running on Vercel and the project is on Next.js 14.
```import * as schema from '@/server/db/schema'
import {sql} from '@vercel/postgres'
import {drizzle} from 'drizzle-orm/vercel-postgres'
export const db = drizzle(sql, {schema})
```
```
const updatedUser = await db.transaction(async (trx) => {
const [updatedUser] = await trx
.update(UsersTable)
.set({
name: input.name,
email: input.email,
})
.where(eq(UsersTable.id, user.id))
.returning();
// ERROR happens here
await trx.insert(KeyTable).values({
id: 'some-id',
userId: user.id,
hashedPassword: 'hashed-password',
});
await trx.delete(KeyTable).where(eq(KeyTable.id, 'oldKeyId'));
return updatedUser
});
```
Contributor guide
Assessment
This issue has not been assessed yet.