Skip to content

Reading converter executed for generated 'countBy' method (r2dbc) #1728

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

Closed
kdebski85 opened this issue Jan 29, 2024 · 3 comments
Closed

Reading converter executed for generated 'countBy' method (r2dbc) #1728

kdebski85 opened this issue Jan 29, 2024 · 3 comments
Labels
status: duplicate A duplicate of another issue

Comments

@kdebski85
Copy link

After upgrade to org.springframework.data:spring-data-r2dbc:3.2.2, reading converter is executed for generated countBy methods.
In 3.2.1 and before, the converter was not executed as expected
Maybe the fix for #1710 is related.

Sample repository with countBy method:

public interface FooRepository extends BaseRepository<Foo, String> extends org.springframework.data.repository.reactive.ReactiveCrudRepository {

   Mono<Long> countByBar(String bar); 
}

Sample reading converter for the entity:

@Component
@ReadingConverter
class ReadConverter implements org.springframework.core.convert.converter.Converter<Row, Foo> {

    public Foo convert(Row source) {
            Foo.FooBuilder entity = Foo.builder();
            entity.name(source.get("name", String.class));
            return entity.build();
    }
}

As a result, the converter fails because it expects to retrieve name column, but only count column is returned:

org.springframework.core.convert.ConversionFailedException: Failed to convert from type [io.r2dbc.postgresql.PostgresqlRow] to type [foo.Foo] for value [io.r2dbc.postgresql.PostgresqlRow@1e52c3ea]
	at org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:47)
	Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: 
Assembly trace from producer [reactor.core.publisher.FluxHandleFuseable] :
	reactor.core.publisher.Flux.handle
	io.r2dbc.postgresql.PostgresqlResult.map(PostgresqlResult.java:113)
Error has been observed at the following site(s):
	*___________Flux.handle ⇢ at io.r2dbc.postgresql.PostgresqlResult.map(PostgresqlResult.java:113)
	*__________Flux.flatMap ⇢ at org.springframework.r2dbc.core.DefaultFetchSpec.lambda$all$1(DefaultFetchSpec.java:78)
	*________Flux.usingWhen ⇢ at org.springframework.r2dbc.core.DefaultDatabaseClient.inConnectionMany(DefaultDatabaseClient.java:143)
	|_      Flux.onErrorMap ⇢ at org.springframework.r2dbc.core.DefaultDatabaseClient.inConnectionMany(DefaultDatabaseClient.java:155)
	|_                      ⇢ at org.springframework.r2dbc.core.DefaultFetchSpec.all(DefaultFetchSpec.java:76)
	|_            Flux.next ⇢ at org.springframework.r2dbc.core.DefaultFetchSpec.first(DefaultFetchSpec.java:71)
	|_          Mono.handle ⇢ at org.springframework.data.r2dbc.core.R2dbcEntityTemplate$UnwrapOptionalFetchSpecAdapter.first(R2dbcEntityTemplate.java:872)
	|_         Mono.flatMap ⇢ at org.springframework.data.r2dbc.core.R2dbcEntityTemplate$EntityCallbackAdapter.first
(...)
Caused by: java.util.NoSuchElementException: Column name 'name' does not exist in column names [count]
	at io.r2dbc.postgresql.PostgresqlRow.getColumn(PostgresqlRow.java:176)
	at io.r2dbc.postgresql.PostgresqlRow.get(PostgresqlRow.java:85)
	at foo.FooConverter$ReadConverter.convert(FooConverter.java:44)

The converter should not be called at all for countBy method.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jan 29, 2024
@mp911de mp911de added the status: waiting-for-feedback We need additional information before we can continue label Jan 29, 2024
@mp911de
Copy link
Member

mp911de commented Jan 29, 2024

This should be fixed via #1723. Care to retest against the latest snapshots?

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Jan 29, 2024
@kdebski85
Copy link
Author

I checked that the issue is resolved in spring-data-r2dbc 3.2.3-SNAPSHOT. Thank you!
Should I close this ticket?

@mp911de
Copy link
Member

mp911de commented Jan 31, 2024

Thanks for your feedback. I'm closing this one as duplicate.

@mp911de mp911de closed this as not planned Won't fix, can't repro, duplicate, stale Jan 31, 2024
@mp911de mp911de added status: duplicate A duplicate of another issue and removed status: waiting-for-triage An issue we've not yet triaged status: feedback-provided Feedback has been provided labels Jan 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

3 participants