typeorm-transactional-cls-hooked icon indicating copy to clipboard operation
typeorm-transactional-cls-hooked copied to clipboard

QueryRunnerAlreadyReleasedError after runOnTransactionRollback

Open herenickname opened this issue 4 years ago • 4 comments

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.

herenickname avatar Jan 05 '21 03:01 herenickname

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

cassinaooo avatar Jan 20 '21 23:01 cassinaooo

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

odavid avatar Jan 21 '21 11:01 odavid

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

herenickname avatar Jan 21 '21 12:01 herenickname

@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()

odavid avatar Jan 21 '21 13:01 odavid