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][Spring Data Cosmos] PartitionKey of type UUID broken since 3.7.0 #23534

Closed
witi83 opened this issue Aug 12, 2021 · 3 comments
Closed

[BUG][Spring Data Cosmos] PartitionKey of type UUID broken since 3.7.0 #23534

witi83 opened this issue Aug 12, 2021 · 3 comments
Assignees
Labels
azure-spring-cosmos Spring cosmos related issues. bug This issue requires a change to an existing behavior in the product in order to be resolved. Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team

Comments

@witi83
Copy link

witi83 commented Aug 12, 2021

Describe the bug
This change broke the support for queries with PartitionKey of type UUID.

Exception or Stack Trace

java.lang.IllegalArgumentException: Unable to construct PartitionKeyInternal from objects array

        at com.azure.cosmos.implementation.routing.PartitionKeyInternal.fromObjectArray(PartitionKeyInternal.java:137)

        at com.azure.cosmos.implementation.routing.PartitionKeyInternal.fromObjectArray(PartitionKeyInternal.java:100)

        at com.azure.cosmos.models.PartitionKey.<init>(PartitionKey.java:31)

        at com.azure.spring.data.cosmos.core.CosmosTemplate.lambda$findItemsAsFlux$28(CosmosTemplate.java:860)

To Reproduce

data class User(
    val id: String,
    @PartitionKey val partitionKey: UUID
)

@Repository
interface UserRepository : CosmosRepository<User, String> {
    fun findByPartitionKey(partitionKey: UUID): Optional<User>
}

When you try to query it using repository.findByPartitionKey(UUID.randomUUID()) you get the above mentioned exception.

Additional information
Please note that IDs of type UUID are still not supported by azure-spring-data, which is really sad given the fact that UUIDs are handled as simple Strings in CosmosDB

@ghost ghost added needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Aug 12, 2021
@chenrujun chenrujun added bug This issue requires a change to an existing behavior in the product in order to be resolved. Client This issue points to a problem in the data-plane of the library. and removed question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Aug 16, 2021
@ghost ghost removed the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Aug 16, 2021
@chenrujun chenrujun added the azure-spring-cosmos Spring cosmos related issues. label Aug 16, 2021
@ghost ghost added the needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team label Aug 16, 2021
@witi83
Copy link
Author

witi83 commented Sep 9, 2021

@chenrujun any news?

@kushagraThapar
Copy link
Member

kushagraThapar commented Sep 20, 2021

@witi83 - UUID PartitionKey was never supported by spring data cosmos SDK. It is just that the error started surfacing since that PR supported partition key support for single partition queries in the above PR.

UUID type is now supported for Id, I have introduced it here - #24198
Support for UUID type for Partition Key is not supported through underlying azure-cosmos Java SDK. So spring data cosmos SDK cannot support it yet.

The reason for this unsupported UUID type as partition key is because UUID cannot be serialized / deserialized by JSON properly. Also, UUID needs to be read by cosmos db in both upper case / lower case without any discrepancy.
Due to these above reasons, we recommend only using String as partition key.

@witi83
Copy link
Author

witi83 commented Sep 21, 2021

@kushagraThapar Thanks for the explanation. It makes sense to me!

@github-actions github-actions bot locked and limited conversation to collaborators Apr 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
azure-spring-cosmos Spring cosmos related issues. bug This issue requires a change to an existing behavior in the product in order to be resolved. Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team
Projects
None yet
Development

No branches or pull requests

3 participants