odavid / typeorm-transactional-cls-hooked

A Transactional Method Decorator for typeorm that uses cls-hooked to handle and propagate transactions between different repositories and service methods. Inpired by Spring Trasnactional Annotation and Sequelize CLS
MIT License
522 stars 86 forks source link

QueryRunnerAlreadyReleasedError after runOnTransactionRollback #80

Open herenickname opened 3 years ago

herenickname commented 3 years ago

I have a @Transactional() function with runOnTransactionRollback(() => this.someRepository.save()) in it. So, when the function caught error and rejects with rollback, the this.someRepository.save() have called and then I receive the QueryRunnerAlreadyReleasedError error.

cassinaooo commented 3 years ago

Hi @ekifox, can you provide a minimal sample repo?

odavid commented 3 years ago

Hi @ekifox / @cassinaooo - Sorry for the late response. I missed this one. Basically, the runOnTransactionRollback() and all the other Hooks, are informal only, and cannot be used to do database operations with the same repository.

I believe an external try/catch should be used instead

herenickname commented 3 years ago

@odavid so, how can I can solve my case? I need to save information to database when the all transaction has failed.

odavid commented 3 years ago

@ekifox - As I said, the solution for that is to use an external (in the Transactional context) to call the transactional method with a try/catch block In the catch block you can call the repository.save()