-
Notifications
You must be signed in to change notification settings - Fork 37.7k
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
SQL supplier in R2DBC DatabaseClient
is eagerly invoked
#29367
Labels
in: data
Issues in data modules (jdbc, orm, oxm, tx)
status: backported
An issue that has been backported to maintenance branches
type: enhancement
A general enhancement
Milestone
Comments
spring-projects-issues
added
the
status: waiting-for-triage
An issue we've not yet triaged or decided on
label
Oct 23, 2022
simonbasle
added
type: documentation
A documentation task
type: enhancement
A general enhancement
and removed
status: waiting-for-triage
An issue we've not yet triaged or decided on
labels
Jan 24, 2023
simonbasle
added a commit
to simonbasle/spring-framework
that referenced
this issue
Jan 25, 2023
This commit modifies the `DefaultDatabaseClient` implementation in order to ensure lazier usage of the `Supplier<String>` passed to the sql method (`DatabaseClient#sql(Supplier)`). Since technically `DatabaseClient` is an interface that could have 3rd party implementations, the lazyness expectation is only hinted at in the `DatabaseClient#sql` javadoc. Possible caveat: some log statements attempt to reflect the now lazily resolved SQL string. Similarly, some exceptions can capture the SQL that caused the issue if known. We expect that these always occur after the execution of the statement has been attempted (see `ResultFunction`). At this point the SQL string will be accessible and logs and exceptions should reflect it as before. Keep an eye out for such strings turning into `null` after this change, which would indicate the opposite. Closes spring-projectsgh-29367
simonbasle
added
the
for: backport-to-5.3.x
Marks an issue as a candidate for backport to 5.3.x
label
Jan 26, 2023
github-actions
bot
added
status: backported
An issue that has been backported to maintenance branches
and removed
for: backport-to-5.3.x
Marks an issue as a candidate for backport to 5.3.x
labels
Jan 26, 2023
simonbasle
added a commit
that referenced
this issue
Jan 26, 2023
This commit modifies the `DefaultDatabaseClient` implementation in order to ensure lazier usage of the `Supplier<String>` passed to the sql method (`DatabaseClient#sql(Supplier)`). Since technically `DatabaseClient` is an interface that could have 3rd party implementations, the lazyness expectation is only hinted at in the `DatabaseClient#sql` javadoc. Possible caveat: some log statements attempt to reflect the now lazily resolved SQL string. Similarly, some exceptions can capture the SQL that caused the issue if known. We expect that these always occur after the execution of the statement has been attempted (see `ResultFunction`). At this point the SQL string will be accessible and logs and exceptions should reflect it as before. Keep an eye out for such strings turning into `null` after this change, which would indicate the opposite. Backport of d72df5a See gh-29367 Closes gh-29887
mdeinum
pushed a commit
to mdeinum/spring-framework
that referenced
this issue
Jun 29, 2023
This commit modifies the `DefaultDatabaseClient` implementation in order to ensure lazier usage of the `Supplier<String>` passed to the sql method (`DatabaseClient#sql(Supplier)`). Since technically `DatabaseClient` is an interface that could have 3rd party implementations, the lazyness expectation is only hinted at in the `DatabaseClient#sql` javadoc. Possible caveat: some log statements attempt to reflect the now lazily resolved SQL string. Similarly, some exceptions can capture the SQL that caused the issue if known. We expect that these always occur after the execution of the statement has been attempted (see `ResultFunction`). At this point the SQL string will be accessible and logs and exceptions should reflect it as before. Keep an eye out for such strings turning into `null` after this change, which would indicate the opposite. Closes spring-projectsgh-29367
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
in: data
Issues in data modules (jdbc, orm, oxm, tx)
status: backported
An issue that has been backported to maintenance branches
type: enhancement
A general enhancement
Affects
spring-r2dbc
5.3.23The R2DBC
DatabaseClient
offers two methods to provide the SQL query:GenericExecuteSpec sql(String sql);
GenericExecuteSpec sql(Supplier<String> sqlSupplier);
We were expecting that the latter would evaluate the
sqlSupplier
lazily, i.e. deferred until subscription. For example we were attempting to use this supplier for large or dynamic queries which we would like to build only in cases where thePublisher
is actually subscribed.However, it seems that the
sqlSupplier
is being invoked eagerly on assembly. For example this test doesn't pass:The issue appears to happen in
DefaultGenericExecuteSpec#execute
, which eagerly invokes thesqlSupplier
to hold a reference and pass it to several steps of the processing, see:spring-framework/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/DefaultDatabaseClient.java
Lines 325 to 329 in 5ea8ba1
As a workaround, we are currently wrapping the chain in a
Mono.defer(() -> ...)
, but this is inconvenient and easy to forget.The text was updated successfully, but these errors were encountered: