Skip to content

fix(spring-config): unwrap DataSource at SpringTransactionContextValidator and use it at isInActiveReadWriteTransaction() - #95

Merged
rawo merged 1 commit into
mainfrom
bugfix/issue-91
Jul 30, 2026
Merged

fix(spring-config): unwrap DataSource at SpringTransactionContextValidator and use it at isInActiveReadWriteTransaction()#95
rawo merged 1 commit into
mainfrom
bugfix/issue-91

Conversation

@rawo

@rawo rawo commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

#91

Approach:

  • Extracted the unwrapDataSource/Unwrapped/describeUnwrap logic out of OutboxAutoConfiguration's companion object into a new top-level internal utility, DataSourceUnwrapping.kt. This was the real fix for the class of bug, not just this instance — the two checks had already drifted apart once specifically because this logic wasn't shared; leaving it in OutboxAutoConfiguration's companion and having SpringTransactionContextValidator reach into an @autoConfiguration class for a utility function would also have been architecturally backwards.
  • SpringTransactionContextValidator now resolves the unwrapped target once at construction time (not per-publish(), since it's on the hot path and identity never changes after wiring), and uses that for getResource(). An unresolvable chain (cycle / null target) now fails fast at bean-construction time with an actionable message, consistent with this codebase's existing fail-fast philosophy, rather than letting every future publish() mysteriously fail validation.
  • Moved the unwrapDataSource unit tests to a new DataSourceUnwrappingTest.kt alongside the utility (previously buried in OutboxAutoConfigurationTransactionRunnerTest.kt), and simplified the now-top-level references (no more OutboxAutoConfiguration.Companion.Unwrapped.Resolved qualification noise).
  • Added 3 new tests to SpringTransactionContextValidatorTest.kt: single-level proxy resolves to the raw target, a nested chain resolves correctly, and an unresolvable chain throws at construction.

…dator and use it at isInActiveReadWriteTransaction()
Copilot AI review requested due to automatic review settings July 30, 2026 12:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a mismatch between Okapi’s startup validation and runtime transaction validation when the outbox DataSource is a Spring DelegatingDataSource proxy (e.g., TransactionAwareDataSourceProxy). It centralizes DataSource unwrapping logic so both checks agree on DataSource identity and avoids per-publish() unwrapping by resolving once at validator construction time.

Changes:

  • Extracted DelegatingDataSource chain-unwrapping into a shared internal utility (DataSourceUnwrapping.kt) and updated startup validation to use it.
  • Updated SpringTransactionContextValidator to resolve (unwrap) the effective DataSource once during construction and validate transactions against that resolved target.
  • Reorganized and expanded tests: moved unwrapping unit tests into DataSourceUnwrappingTest.kt and added runtime validator coverage for proxied, nested, and cyclic/unresolvable chains.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
okapi-spring-boot/src/main/kotlin/com/softwaremill/okapi/springboot/DataSourceUnwrapping.kt Introduces shared internal unwrapping result types and unwrapping/diagnostic helpers for DelegatingDataSource chains.
okapi-spring-boot/src/main/kotlin/com/softwaremill/okapi/springboot/SpringTransactionContextValidator.kt Uses the shared unwrapping utility to validate against the resolved backing DataSource (fail-fast on unresolvable chains).
okapi-spring-boot/src/main/kotlin/com/softwaremill/okapi/springboot/OutboxAutoConfiguration.kt Removes duplicated unwrapping implementation from the companion object and relies on the shared utility in startup checks.
okapi-spring-boot/src/test/kotlin/com/softwaremill/okapi/springboot/DataSourceUnwrappingTest.kt Adds focused unit tests for unwrapping behavior (nested proxies, null targets, cycles).
okapi-spring-boot/src/test/kotlin/com/softwaremill/okapi/springboot/SpringTransactionContextValidatorTest.kt Adds tests ensuring runtime validation succeeds behind proxies and fails fast for cyclic/unresolvable chains.
okapi-spring-boot/src/test/kotlin/com/softwaremill/okapi/springboot/OutboxAutoConfigurationTransactionRunnerTest.kt Removes the previously embedded unwrapping tests now covered by DataSourceUnwrappingTest.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@rawo
rawo merged commit 458f5b6 into main Jul 30, 2026
9 checks passed
@rawo
rawo deleted the bugfix/issue-91 branch July 30, 2026 13:00
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