microsoft / spring-data-cosmosdb

Access data with Azure Cosmos DB
MIT License
94 stars 64 forks source link

The FindById and findByIdAndPartitionKey implementation don't comply with javadoc #451

Closed apescione closed 4 years ago

apescione commented 4 years ago

Version: 2.1.8

Both APIs FindById and findByIdAndPartitionKey should return Optional#empty() when a Entity hasn't been found, instead, a DocumentDBAccessException is thrown.

Below the documentation for findByIdAndPartitionKey in com.microsoft.azure.spring.data.cosmosdb.repository.DocumentDbRepository<T, ID>

    /**
     * Retrieves an entity by its id.
     *
     * @param id must not be {@literal null}.
     * @param partitionKey partition key value of entity, must not be null.
     * @return the entity with the given id or {@literal Optional#empty()} if none found
     * @throws IllegalArgumentException if {@code id} is {@literal null}.
     */
    Optional<T> findById(ID id, PartitionKey partitionKey);

This behavior will force to catch always the exception when an entity is not found. DocumentDBAccessException may be thrown when other kind of errors occur.

kushagraThapar commented 4 years ago

Verified at our end, findById API is behaving correctly, but findById which takes partitionKey as well has this bug. Will fix it soon.

kushagraThapar commented 4 years ago

@ apescione This has been fixed and released in v2.1.9.

Will be fixed and released in v2.2.1.M2 in few days. .

kushagraThapar commented 4 years ago

This has been fixed in v2.2.1 as well. Closing this issue now.