Skip to content

[BUG] ReactiveCosmosTemplate existsById does not work as intended #40019

Description

@NetsCreationLab

Describe the bug
The implementation for existsById in com.azure.spring.data.cosmos.core.ReactiveCosmosTemplate indicates that a Mono emitting true if the element exists, or false if the element does not exist. However, the implementation checks if the result emitted by findById is null, which cannot happen, as an empty Mono is returned by findById in case no element is found.

Exception or Stack Trace
N/A

To Reproduce
Use existsById to look for an element that does not exist, and observe that an empty Mono is returned in place of a Mono emitting false.

Code Snippet

    /**
     * Exists
     *
     * @param id the id
     * @param domainType the entity class
     * @param containerName the container name
     * @return Mono with a boolean or error
     */
    public Mono<Boolean> existsById(Object id, Class<?> domainType, String containerName) {
        return findById(containerName, id, domainType)
            .flatMap(o -> Mono.just(o != null));
    }

Expected behavior
Returned Mono should emit true if the element is present and false if the element is not present.

Screenshots
If applicable, add screenshots to help explain your problem.

Setup (please complete the following information):

  • OS: N/A
  • IDE: IntelliJ
  • Library/Libraries: com.azure.spring:spring-cloud-azure-starter-data-cosmos:4.10.0
  • Java version: N/A
  • App Server/Environment: N/A
  • Frameworks: Spring Boot

Additional context
https://github.com/reactive-streams/reactive-streams-jvm#user-content-2.13
https://stackoverflow.com/questions/69461051/why-cant-a-mono-hold-a-null

Information Checklist
Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report

  • Bug Description Added
  • Repro Steps Added
  • Setup information Added

Metadata

Metadata

Assignees

Labels

ClientThis issue points to a problem in the data-plane of the library.azure-springAll azure-spring related issuescustomer-reportedIssues that are reported by GitHub users external to the Azure organization.needs-team-attentionWorkflow: This issue needs attention from Azure service team or SDK teamquestionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that

Type

No type

Fields

No fields configured for issues without a type.

Projects

Status
Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions