Skip to content

[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

Merged
merged 11 commits into from
Jun 19, 2025
Merged

Conversation

bambriz
Copy link
Member

@bambriz bambriz commented Jun 18, 2025

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.

…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.
@Copilot Copilot AI review requested due to automatic review settings June 18, 2025 07:38
@bambriz bambriz requested a review from a team as a code owner June 18, 2025 07:38
Copy link
Contributor

@Copilot Copilot AI left a 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 or PartitionKey instance and default missing version 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

Copy link

github-actions bot commented Jun 18, 2025

API Change Check

APIView identified API level changes in this PR and created the following API reviews

azure-cosmos

Copy link
Member

@Pilchie Pilchie left a 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.

Copy link
Member

@tvaron3 tvaron3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@xinlian12 xinlian12 left a 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 👍

@bambriz
Copy link
Member Author

bambriz commented Jun 19, 2025

/azp run python - cosmos - tests

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@bambriz
Copy link
Member Author

bambriz commented Jun 19, 2025

/azp run python - cosmos - tests

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@bambriz
Copy link
Member Author

bambriz commented Jun 19, 2025

/check-enforcer override

CI has previously passed, latest commit is updating version

Copy link
Member

@kushagraThapar kushagraThapar left a 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.

@kushagraThapar kushagraThapar merged commit 05b716d into Azure:main Jun 19, 2025
21 checks passed
@tvaron3 tvaron3 mentioned this pull request Jun 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

5 participants