Transaction rollback does not work
luaneyed opened this issue · 2 comments
luaneyed commented
try {
await Connection.transaction({ models: [ModelClass] }, (ModelClassTx) => {
// [Job 1] do something using ModelClassTx
throw new Error('An intentional error');
// [Job 2] do something using ModelClassTx
return Promise.resolve();
});
} catch (error) {
return { error };
}
I expect the above code affect nothing to db, but Job 1
is committed!
Exactly, the job is committed when MySQLAdapter::rollbackTransaction
is executed.
sixmen commented
I already have a test case for that.
cormo/test/cases/transaction_bind.ts
Line 29 in b782cc9
Please give a more detail for the problem.
luaneyed commented
I solved it.
All queries should be executed before returning the transaction block.
I think it's just a matter of order.
[ what I wanted ]
START TRANSACTION
SQL-1
SQL-2
ROLLBACK
[ what happened with my asynchronous code ]
START TRANSACTION
ROLLBACK
SQL-1
SQL-2