FIX: Rethrow error in commit path of callbacks #3147
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Actual behaviour
If you have callbacks in your transaction and they fail due any reason, the error is just added to the log and subsequent callbacks will be invoked and finally the transaction will be commited
Expected behaviour
If a callback in the commit path (preCommit/postCommit) has a problem, the exception should be thrown up to the caller and the transaction should NOT be committed, if a preCommit hook fails.
In our situation, we performed a DB.save on an entity. The preCommit hook on that entity performed some DB access in an nested transaction. The JDBC driver failed with an error and the nested transaction perfomed a roll-back. As there were no save-points involved, the whole transaction is rolled back. For the caller the
DB.save
seems to be successful. We discovered the error, when we reviewed the logs and see that there was a problem.Our suggestion is, that exceptions, that happen in a "preCommit" or "postCommit" hook should always be rethrown up to the caller.
For "preRollback" and "postRollback" we are a bit unsure, and we keep the behaviour as it is (log exception and continue)