Repository navigation
fix: correctly isolate db constraint violations during review submission - #146
huytran2005 wants to merge 2 commits into
Conversation
…ervice component Refactored `ExcursionReviewRepository` to remove the `@Transactional(propagation = Propagation.REQUIRES_NEW)` override on the `save` method, which is generally ignored by Spring AOP when placed directly on a Spring Data repository interface. To achieve the correct isolation behavior for handling potential database constraints, introduced a dedicated `ExcursionReviewWriter` Spring component containing a `REQUIRES_NEW` method that explicitly calls `saveAndFlush`. This correctly isolates constraint errors preventing the outer transaction from being marked as rollback-only. Modified `ExcursionReviewService` and the associated unit tests to mock and utilize the new writer. Co-authored-by: huytran2005 <[email protected]>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 57 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
…ervice component Refactored `ExcursionReviewRepository` to remove the `@Transactional(propagation = Propagation.REQUIRES_NEW)` override on the `save` method, which is generally ignored by Spring AOP when placed directly on a Spring Data repository interface. To achieve the correct isolation behavior for handling potential database constraints, introduced a dedicated `ExcursionReviewWriter` Spring component containing a `REQUIRES_NEW` method that explicitly calls `saveAndFlush`. This correctly isolates constraint errors preventing the outer transaction from being marked as rollback-only. Modified `ExcursionReviewService` and the associated unit tests to mock and utilize the new writer, and added `ExcursionReviewWriterTest` to satisfy SonarCloud's new code coverage requirements. Co-authored-by: huytran2005 <[email protected]>
|
|
Closing redundant draft PR created by automated bot. |



Problem Statement & Rationale:
The previous implementation in
ExcursionReviewRepositoryattempted to isolate database constraint violations by overriding thesavemethod with@Transactional(propagation = Propagation.REQUIRES_NEW). However, Spring's AOP proxy frequently ignores propagation attributes on generic, overridden Spring Data JPA repository methods, meaning the nested save happens in the same outer transaction. If a database constraint failure occurs (like idempotency key violations), it marks the parent transaction as rollback-only, and any surroundingtry-catchblocks fail to recover it, eventually causing aTransactionSystemException.Summary of Code and Test Changes:
ExcursionReviewWriter, a new@Serviceclass that explicitly handles thesaveAndFlush()operation with@Transactional(propagation = Propagation.REQUIRES_NEW).savemethod fromExcursionReviewRepositoryinterface.ExcursionReviewServiceto inject and utilizeExcursionReviewWriterfor savingExcursionReviewentities instead of calling the repository directly.ExcursionReviewAndAnalyticsTestto verify and mock the newExcursionReviewWriterbehavior and ensure all unit assertions correctly interact with the isolated transaction handler.Verification Commands Executed and Test Results:
chmod +x mvnw./mvnw install -DskipTests(To prepare cross-module dependencies, resolving cruise-common build issues)./mvnw testAll unit and integration tests across the multi-module Maven project run correctly, passing successfully without regressions (806 total tests passed, 0 failures, 0 errors).
Residual Limitations or Human Review Recommendations:
None. The code achieves robust transactional consistency for constraint isolation and adheres to Spring Boot best practices.
PR created automatically by Jules for task 4844229892463700539 started by @huytran2005