Skip to content
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

[BUG] Repository Method Optional<T> findById(ID id) breaking contract by throwing ResourceNotFoundException on 404 #369

Open
Scy147 opened this issue Nov 15, 2024 · 1 comment
Labels
bug Something isn't working untriaged

Comments

@Scy147
Copy link

Scy147 commented Nov 15, 2024

What is the bug?

Given the following Repository
@Repository public interface IndexDocumentRepository extends ElasticsearchRepository<IndexDocument, UUID>{ }

Calling IndexDocumentRepository.findById(UUID) with a return value of Optional<IndexDocument> may result in a org.springframework.data.elasticsearch.ResourceNotFoundException

How can one reproduce the bug?

Assuming the connection is setup and an Index exists, just calling findById(UUID.randomUUID()) should reproduce this bug

What is the expected behavior?

When the Index eixsts, but no Document with the given ID exists, the return value should be null

What is your host/environment?

Dependencies used:
Spring boot 3.3.1 with relevant starters
AWS SDK 2.27.10
spring-data-opensearch 1.5.2

Do you have any screenshots?

Excerpt of the stacktrace

org.springframework.data.elasticsearch.ResourceNotFoundException: server returned 404
at org.opensearch.data.client.osc.OpenSearchExceptionTranslator.translateExceptionIfPossible(OpenSearchExceptionTranslator.java:92)
at org.opensearch.data.client.osc.OpenSearchExceptionTranslator.translateException(OpenSearchExceptionTranslator.java:63)
at org.opensearch.data.client.osc.OpenSearchTemplate.execute(OpenSearchTemplate.java:700)
at org.opensearch.data.client.osc.OpenSearchTemplate.get(OpenSearchTemplate.java:148)
at org.springframework.data.elasticsearch.repository.support.SimpleElasticsearchRepository.lambda$findById$0(SimpleElasticsearchRepository.java:115)
at org.springframework.data.elasticsearch.repository.support.SimpleElasticsearchRepository.execute(SimpleElasticsearchRepository.java:448)
at org.springframework.data.elasticsearch.repository.support.SimpleElasticsearchRepository.findById(SimpleElasticsearchRepository.java:115)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:355)
at org.springframework.data.repository.core.support.RepositoryMethodInvoker$RepositoryFragmentMethodInvoker.lambda$new$0(RepositoryMethodInvoker.java:277)
at org.springframework.data.repository.core.support.RepositoryMethodInvoker.doInvoke(RepositoryMethodInvoker.java:170)
at org.springframework.data.repository.core.support.RepositoryMethodInvoker.invoke(RepositoryMethodInvoker.java:158)
at org.springframework.data.repository.core.support.RepositoryComposition$RepositoryFragments.invoke(RepositoryComposition.java:516)
at org.springframework.data.repository.core.support.RepositoryComposition.invoke(RepositoryComposition.java:285)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$ImplementationMethodExecutionInterceptor.invoke(RepositoryFactorySupport.java:628)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.doInvoke(QueryExecutorMethodInterceptor.java:173)
at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.invoke(QueryExecutorMethodInterceptor.java:148)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:223)
at jdk.proxy2/jdk.proxy2.$Proxy295.findById(Unknown Source)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:355)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:196)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:138)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:223)
at jdk.proxy2/jdk.proxy2.$Proxy296.findById(Unknown Source)

Do you have any additional context?

The Project is currently being updated from an older Spring version that was still using the Elasticsearch libraries, other calls to the opensearch instance do already work (for example, IndexOperations.existsTemplate)

@Scy147 Scy147 added bug Something isn't working untriaged labels Nov 15, 2024
@reta
Copy link
Collaborator

reta commented Nov 18, 2024

@Scy147 I have troubles reproducing this issue, do you have a test case / reproducer to share? thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working untriaged
Projects
None yet
Development

No branches or pull requests

2 participants