fix: add missing partition key kind for simple partition keys (#1342) - #1429
Open
kauanmodolo wants to merge 1 commit into
Open
fix: add missing partition key kind for simple partition keys (#1342)#1429kauanmodolo wants to merge 1 commit into
kauanmodolo wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
When using a simple partition key with the
@CosmosPartitionKeydecorator (e.g.,@CosmosPartitionKey('userId')), the application fails at runtime with the following error:Error: Missing partition key kind in the partition key path policyThis happens because the latest Azure Cosmos DB SDK requires the
kindandversionproperties to be explicitly defined in the partition key configuration. The current implementation only sets thepathsproperty for simple partition keys, which is no longer sufficient.Example that fails:
Hierarchical partition keys work correctly because they already include the required properties:
Issue Number: #1342
What is the new behavior?
The fix automatically adds the required kind and version properties when a simple string partition key is used:
Simple partition keys now default to:
Hierarchical partition keys continue to work exactly as before (no changes)
After the fix, both scenarios work:
✅ Simple partition key:
✅ Hierarchical partition key:
Does this PR introduce a breaking change?
This is a backward-compatible bug fix. All existing code continues to work:
Simple partition keys that were broken are now fixed
Hierarchical partition keys continue to work as before
No API changes or behavioral changes for existing working code
Other information
Changes made:
Updated lib/cosmos-db/cosmos-db.providers.ts:
Added imports for PartitionKeyKind and PartitionKeyDefinitionVersion
Added logic to detect if partition key is a simple string or hierarchical object
Automatically add kind and version for simple partition keys
Updated PartitionKeyValues interface to support both string and object types