kysely-org / kysely

A type-safe typescript SQL query builder
https://kysely.dev
MIT License
10.22k stars 259 forks source link

Rollback doesnt trigger on error #899

Closed revofusion closed 6 months ago

revofusion commented 6 months ago

I have a kysely transaction where I update 2 rows

In the case of a thrown error from the transaction, the updates are not rolled back

Error:

PostgresError: column "address" of relation "txs" does not exist at ErrorResponse (/server/node_modules/postgres/cjs/src/connection.js:790:26) at handle (/server/node_modules/postgres/cjs/src/connection.js:476:6) at Socket.data (/server/node_modules/postgres/cjs/src/connection.js:315:9) at Socket.emit (node:events:511:28) at addChunk (node:internal/streams/readable:332:12) at readableAddChunk (node:internal/streams/readable:305:9) at Socket.Readable.push (node:internal/streams/readable:242:10) at TCP.onStreamRead (node:internal/stream_base_commons:190:23) { severity_local: 'ERROR', severity: 'ERROR', code: '42703', position: '112', file: 'parse_target.c', line: '1272', routine: 'checkInsertTargets' }

I understand the error was due to the column not existing, however I would expect the updates to still be rolled back

Code

          await kysely.transaction().execute(async (trx) => {
            const [row1, row2] = await Promise.all([
              updateRow1(trx),
              updateRow2(trx),
            ]);
          })

Even after the error from the transaction, the updateRow changes persist

koskimas commented 6 months ago

Yep, nope. The error is somewhere in your code, or alternatively you're using a 3rd party dialect that has a broken transaction implementation.

Kysely is extensively tested, and stuff like this would get caught in the tests.

koskimas commented 6 months ago

My guess is that updateRow accidentally uses the global kysely instance instead of the trx passed in.