Rollback not happening on tx.rollback() [PG DRIVER]
I've tried a couple different approachs (throwing errors etc, keeps the same issue)
3 Replies
Also tried without try catch
The first query inside the transaction uses the db object, basically bypassing the transaction and running the query in a different connection. You have to use the
tx
object passed to the callback.
Also, I'm not sure how smart is it to pass an async function to forEach. I would advice to use for await (const category of categories)
The async callback passed to forEach is very likely running in a different async context to the transaction, so if an error gets thrown, that call back doesn't know about it. Furthermore, throwing inside, probably doesn't reach to the transaction callback
Worst of all, the transaction callback is probably returning before the forEach even gets a chance to be calledThank you, I actually just learned about the async callback!