-
Notifications
You must be signed in to change notification settings - Fork 3k
[Cosmos] Hash v1 Key Error Hotfix #41639
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
Conversation
…umber in partition key definition. Some legacy hash v1 containers don't always provide version number for partition key defintion which results in some key error exceptions. This fixes that by allowing a dictionary or PartitionKey instanced to be passed into the constructor of PartitionKeys, when done that way if no version number is available, we default the value to 1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR provides a hotfix for legacy Cosmos DB hash v1 containers that may omit the version
field in their partition key definition. Key changes include:
- Extending
PartitionKey
to accept a dict orPartitionKey
instance and default missingversion
to 1 - Replacing explicit
PartitionKey(path, kind, version)
calls with the new dict overload throughout sync and async code paths - Adding sync and async tests to validate behavior when
version
is missing
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
azure/cosmos/partition_key.py | Added overload to __init__ to accept dict definitions and default version = 1 |
azure/cosmos/container.py | Updated get_partition_key_from_properties to use new overload |
azure/cosmos/aio/* | Simplified all explicit PartitionKey(...) instantiations to use dict overload |
tests/test_changefeed_partition_key_variation.py | Added new sync test for missing version in partition definition |
tests/test_changefeed_partition_key_variation_async.py | Added new async test for missing version in partition definition |
CHANGELOG.md | Documented bug fix for missing version in legacy v1 PK definitions |
sdk/cosmos/azure-cosmos/tests/test_changefeed_partition_key_variation_async.py
Show resolved
Hide resolved
sdk/cosmos/azure-cosmos/tests/test_changefeed_partition_key_variation.py
Show resolved
Hide resolved
API Change CheckAPIView identified API level changes in this PR and created the following API reviews |
sdk/cosmos/azure-cosmos/azure/cosmos/_cosmos_client_connection.py
Outdated
Show resolved
Hide resolved
sdk/cosmos/azure-cosmos/tests/test_changefeed_partition_key_variation.py
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks reasonable to me, but I'll defer to others to sign off.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
sdk/cosmos/azure-cosmos/tests/test_changefeed_partition_key_variation.py
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for the quick fix 👍
/azp run python - cosmos - tests |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run python - cosmos - tests |
Azure Pipelines successfully started running 1 pipeline(s). |
/check-enforcer override CI has previously passed, latest commit is updating version |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks @bambriz for fixing this.
Description
Fixes issue related to hash v1 containers not always having version number in partition key definition.
Some legacy hash v1 containers don't always provide version number for partition key definition which results in some key error exceptions. This fixes that by allowing a dictionary or PartitionKey instanced to be passed into a helper method of PartitionKey that will return a Partitionkey from the passed in partition key definition, when done that way if no version number is available, we default the value to 1.