control-service: code expected to run in transaction now runs in transaction#2117
Merged
control-service: code expected to run in transaction now runs in transaction#2117
Conversation
Signed-off-by: murphp15 <murphp15@tcd.ie>
Signed-off-by: murphp15 <murphp15@tcd.ie>
for more information, see https://pre-commit.ci
Signed-off-by: murphp15 <murphp15@tcd.ie>
Signed-off-by: murphp15 <murphp15@tcd.ie>
Signed-off-by: murphp15 <murphp15@tcd.ie>
Signed-off-by: murphp15 <murphp15@tcd.ie>
Signed-off-by: murphp15 <murphp15@tcd.ie>
mivanov1988
approved these changes
May 25, 2023
antoniivanov
approved these changes
May 25, 2023
Contributor
antoniivanov
left a comment
There was a problem hiding this comment.
How did you verify that the method is now executed within a transaction ?
(could be by looking at logs by setting logging.level.org.springframework.transaction=debug; or debugger or best with unit tests).
Contributor
Author
|
@tozka |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Why
Often the test DataJobTerminationStatusIT fails with the following stacktrace.
I was looking into it and I realised the database operations were not actually taking place in a transaction despite the method being marked as transactional.
It is because calling a method from another method in a the same class stops spring from being able to intercept the function call and start a transaction.
Please see here for more details: https://stackoverflow.com/questions/3423972/spring-transaction-method-call-by-the-method-within-the-same-class-does-not-wo
What
In this PR I create a second class to call the transactional method so it can run in a transaction.
How was this tested
Locally, I was not able to reproduce the randomly failing test. But that is not to say I have 100% fixed it.
But this change is important because the code now does what the original author expected and will avoid cryptic bugs in the future.