Skip to content

Honour a wrapper's unwrap when resolving the root DataSource - #51410

Merged
snicoll merged 2 commits into
spring-projects:4.1.xfrom
jjh75607:fix/unwrap-root-honours-wrapper-unwrap-41x
Aug 24, 2026
Merged

snicoll merged 2 commits into
spring-projects:4.1.xfrom
jjh75607:fix/unwrap-root-honours-wrapper-unwrap-41x

Conversation

@jjh75607

@jjh75607 jjh75607 commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor

DataSourceUnwrapper.unwrapRoot checks the delegate chain and the AOP target before it
looks at Wrapper.unwrap, and it stops as soon as a wrapper unwraps to itself.
unwrap(DataSource, Class, Class), right above it, does the opposite and calls
safeUnwrap first.

DecoratedDataSource from spring-boot-data-source-decorator 2.0.1 extends
DelegatingDataSource and overrides unwrap to return the HikariDataSource, but its
target is datasource-proxy's ProxyDataSource. Following the delegate chain lands on the
proxy, and a Wrapper that implements the requested interface is meant to return itself
from unwrap. The search therefore ends at the proxy and DecoratedDataSource.unwrap
never runs. DataSourceBuilder.derivedFrom is the only caller, so it derives from the proxy instead
of the pool. Nothing throws. Reported downstream as
gavlyukovskiy/spring-boot-data-source-decorator#197.

This calls unwrap first and keeps going through the delegate chain and the AOP target
when a wrapper returns itself. DelegatingDataSource and LazyConnectionDataSourceProxy
both return themselves, so the delegate chain still handles them and the lazy connection
proxy case from #50271 is unaffected. The new test fails on 4.1.x without the change.

jjh75607 added a commit to jjh75607/spring-boot that referenced this pull request Aug 22, 2026
@jjh75607
jjh75607 force-pushed the fix/unwrap-root-honours-wrapper-unwrap-41x branch from 0b29a18 to af23bb6 Compare August 22, 2026 09:17
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Aug 22, 2026
@snicoll snicoll added type: regression A regression from a previous release and removed status: waiting-for-triage An issue we've not yet triaged labels Aug 24, 2026
@snicoll snicoll self-assigned this Aug 24, 2026
@snicoll snicoll added this to the 4.1.2 milestone Aug 24, 2026
@snicoll
snicoll force-pushed the fix/unwrap-root-honours-wrapper-unwrap-41x branch from af23bb6 to d5cec29 Compare August 24, 2026 08:49
@snicoll
snicoll merged commit cbaaa0f into spring-projects:4.1.x Aug 24, 2026
1 check failed
@snicoll

snicoll commented Aug 24, 2026

Copy link
Copy Markdown
Member

Thanks @jjh75607

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: regression A regression from a previous release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants