Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix transactional annotation #419

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Conversation

ushkarev
Copy link
Contributor

@ushkarev ushkarev commented Apr 15, 2023

Spring only creates transactions when calling annotated methods on other classes using a proxy object, invocations on this will not create transactions as the transaction-managing proxy object isn’t used.

🚨 Since transactions haven’t been created in practice, I’m not sure how safe this change is! If our event-receiving leads to DB changes and new events being published, they might be received by third parties prior to data being fully persisted.

@ushkarev ushkarev force-pushed the transactional-annotations branch 2 times, most recently from 1ab4762 to d6e2c24 Compare April 15, 2023 12:21
@@ -344,7 +350,6 @@ class PrisonerIepLevelReviewService(
)
}

@Transactional
Copy link
Contributor Author

@ushkarev ushkarev Apr 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the only existing call to this method is from the processOffenderEvent in this class so the transactional annotation has no effect. but sadly we cannot make it private as there's a test case using it.

@@ -135,6 +135,7 @@ class PrisonerIepLevelReviewService(
suspend fun getReviewById(id: Long): IepDetail =
prisonerIepLevelRepository.findById(id)?.toIepDetail(incentiveLevelService.getAllIncentiveLevelsMapByCode()) ?: throw NoDataFoundException(id)

@Transactional
Copy link
Contributor Author

@ushkarev ushkarev Apr 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding annotation here so all effects of the received event are transactional now… is that too much? is there any harm in createIepForReceivedPrisoner becoming transactional?

Copy link
Contributor Author

@ushkarev ushkarev Apr 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BUT if createIepForReceivedPrisoner or mergedPrisonerDetails were to raise domain events, then they might be received by another party prior to the transaction committing leading to a read of stale data!

neilmendum
neilmendum previously approved these changes Apr 17, 2023
Copy link
Contributor

@neilmendum neilmendum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ushkarev ushkarev force-pushed the transactional-annotations branch 2 times, most recently from f12ad5e to 02806b6 Compare April 20, 2023 14:31
@ushkarev ushkarev force-pushed the transactional-annotations branch from 02806b6 to 29c1977 Compare May 24, 2023 11:22
Spring only creates transactions when calling annotated methods on _other_ classes, invocations on `this` will not create transactions as the proxy object isn't used
@ushkarev ushkarev force-pushed the transactional-annotations branch from 29c1977 to 75a0871 Compare October 16, 2023 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants