-
Notifications
You must be signed in to change notification settings - Fork 38.4k
Unwrap DataSource hidden behind InfrastructureProxy in SqlScriptsTestExecutionListener #26422
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
Comments
Thanks for raising the issue. Are you on Spring Framework 5.3.x? Also, out of curiosity... Do you have custom code that generates the proxy implementing Or is the proxy being created by something in one of the Spring portfolio projects or a third-party library? |
Support for unwrapping proxied data sources has been added in 4a7a225. Feel free to try this out in the upcoming 5.3.4 snapshots and let us know if you run into any issues. |
@sbrannen It is in external library code, not in any Spring portfolio projects. I realized how this worked - and was duly impressed by the logic! - and utilized it. Then, in one of our projects, we got hit by this issue. Thanks! |
in method
SqlScriptsTestExecutionListener.executeSqlScripts(...)
, around line 213, the following code resides:This seems to contradict the logic used in
DataSourceUtils
which handles such equality checks taking into account that aDataSource
may be an implementation ofInfrastrutureProxy
.We have a setup where the
DataSource
in the Spring context is directly the databaseDataSource
(well, it is pooled), while theDataSource
given to theDataSourceTransactionManager
is a wrapped version. However, the wrapping class implementsInfrastructureProxy
, which ensures that all Spring JDBC stuff - which utilizes theDataSourceUtils
class to fetch (and release) Connections - actually handles this perfectly: Even though e.g. theJdbcTemplate
has gotten the "plain"DataSource
, while, again, the TxMgr has the wrappedDataSource
, when in a Spring managed Transaction, theJdbcTemplate
ends up with Connections from the wrappedDataSource
(in theDataSourceTransactionManager
) due to the logic wrt.InfrastructureProxy
inDataSourceUtils
.However, this is not the case in
SqlScriptsTestExecutionListener
, due to the much plainer.equals(..)
check being performed there. Basically, had the check not been there, it would have worked. Also, had the check taken into account theInfrastructureProxy
logic, it would also have worked.(And, due to the equality being checked is
dataSourceFromSpringContext.equals(dataSourceFromTxMgr)
- and not the other way around - I cannot hack this to work either. The only way around that would be to also wrap theDataSource
in the Spring context too (to trick the.equals(..)
) - in which case I could just as well put the sameDataSource
in Spring context as the one given to theDataSourceTransactionManager
, which of course would fix this. However, the problem is that these two are handled in different code bases, and it is not always the situation that we want to do that wrapping of theDataSource
given to theDataSourceTransactionManager
.).The text was updated successfully, but these errors were encountered: