You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm currently using drizzle ORM 0.33.0, specifically with postgres using the drizzle-orm/postgres-js driver. I'm trying to rollback a transaction in a testing scenario but it's failing to rollback as expected.
Specifically, I have a script that uses a transaction to execute two things:
Delete data from tables
Insert data into tables
My test scenario works by first executing the script which deletes data from the tables and then inserts data into the tables. I then introduce an insert error into last table to have data inserted. In this case, I attempt to insert a non numeric into a numeric value, e.g.:
prediction_value: '843.25fff',
instead of
prediction_value: '843.25',
I then execute the script again. What I expect to happen is the second script's transaction fails because step 2 of inserting the data into tables fails. However, the data that was previously inserted in the first script exection is still present in the tables because the rollback should have rolled back any data that were inserted into the tables as well as rolled back the deletion of data. Instead, what I see is the table data being deleted. None of the tables have any data. I also get a transaction rollback error.
I execute this script twice by executing the following npm script twice:
tsx src/drizzle/load-sample-data.ts
When the script is run for the second time (and when I introduce the insert error in the second script execution), I see the "Rollback failed" error with the following stack for the rollbackError:
err: {
"type": "TransactionRollbackError",
"message": "Rollback",
"stack":
DrizzleError: Rollback
at PostgresJsTransaction.rollback (/myproject/node_modules/src/pg-core/session.ts:116:9)
at <anonymous> (/myproject/src/drizzle/load-sample-data.ts:118:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async scope (/myproject/node_modules/postgres/cjs/src/index.js:259:18)
at async Function.begin (/myproject/node_modules/postgres/cjs/src/index.js:242:14)
"name": "DrizzleError"
}
So what's going on? Am I doing something wrong or is there an inherent Drizzle ORM bug? I found a similar issue here, but this seems to indicate the bug is only for sqllite. Is this also a bug in postgres?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm currently using drizzle ORM 0.33.0, specifically with postgres using the drizzle-orm/postgres-js driver. I'm trying to rollback a transaction in a testing scenario but it's failing to rollback as expected.
Specifically, I have a script that uses a transaction to execute two things:
My test scenario works by first executing the script which deletes data from the tables and then inserts data into the tables. I then introduce an insert error into last table to have data inserted. In this case, I attempt to insert a non numeric into a numeric value, e.g.:
prediction_value: '843.25fff',
instead of
prediction_value: '843.25',
I then execute the script again. What I expect to happen is the second script's transaction fails because step 2 of inserting the data into tables fails. However, the data that was previously inserted in the first script exection is still present in the tables because the rollback should have rolled back any data that were inserted into the tables as well as rolled back the deletion of data. Instead, what I see is the table data being deleted. None of the tables have any data. I also get a transaction rollback error.
Here is a snippet of the relevant code:
I execute this script twice by executing the following npm script twice:
tsx src/drizzle/load-sample-data.ts
When the script is run for the second time (and when I introduce the insert error in the second script execution), I see the "Rollback failed" error with the following stack for the rollbackError:
So what's going on? Am I doing something wrong or is there an inherent Drizzle ORM bug? I found a similar issue here, but this seems to indicate the bug is only for sqllite. Is this also a bug in postgres?
Beta Was this translation helpful? Give feedback.
All reactions