Open x302502 opened 3 years ago
This is a common gotcha.
Promise.all()
rejects as soon as the first promise gets rejected, triggering a rollback. If other operations referencing the transaction are still pending, they get orphaned and executed outside the transaction, making it appear as if the rollback did not happen.
You need to use something like Promise.allSettled()
instead, and throw if any promise failed.
I have a function that uses
@Transactional() excute() { ... const promises = []; promises.push(this.receiptDetailRepo.save(listReceiptDetail)) promises.push(this.lotattributeRepo.insert(listLotattribute)) promises.push(this.lotxlocxidRepo.save(listIvUpdate)) promises.push(this.lotxlocxidRepo.insert(listIvInsert)) promises.push(this.itrnRepo.insert(listItrn)) promises.push(Promise.reject("ERROR")); const [resReceiptDetails] = await Promise.all(promises); }
but it doesn't rollback;
What I am missing?