[Cosmos DB] Bug in "Delete Bulk" operation with "undefined" partition key value
See original GitHub issue- Package Name: @azure/cosmos
- Package Version: 3.9.1
- Operating system: macOS
- nodejs
- version: 10.16.3
- browser
- name/version:
- typescript
- version:
- Is the bug related to documentation in
- README.md
- source code documentation
- SDK API docs on https://docs.microsoft.com
Describe the bug When performing the “delete” bulk operation with “undefined” partition key value, the bulk operation fails with the following error:
TypeError: Cannot read property 'replace' of undefined
at getPartitionKeyToHash (/Users/xxx/Projects/yyy/app/node_modules/@azure/cosmos/dist/index.js:919:38)
at /Users/xxx/Projects/yyy/app/node_modules/@azure/cosmos/dist/index.js:5483:39
at Array.forEach (<anonymous>)
at Items.<anonymous> (/Users/xxx/Projects/yyy/app/node_modules/@azure/cosmos/dist/index.js:5480:22)
at Generator.next (<anonymous>)
at fulfilled (/Users/xxx/Projects/yyy/app/node_modules/@azure/cosmos/node_modules/tslib/tslib.js:111:62)
at processTicksAndRejections (internal/process/task_queues.js:89:5)
I believe this is happening because of the following lines of code:
function getPartitionKeyToHash(operation, partitionProperty) {
const toHashKey = hasResource(operation)
? operation.resourceBody[partitionProperty]
: operation.partitionKey.replace(/[\[\]\"\']/g, "");
// We check for empty object since replace will stringify the value
// The second check avoids cases where the partitionKey value is actually the string '{}'
if (toHashKey === "{}" && operation.partitionKey === "[{}]") {
return {};
}
return toHashKey;
}
According to the documentation here, undefined
value is valid for the partition key.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Delete items by partition key value - API for NoSQL (preview)
This article explains how to use the Azure Cosmos DB SDKs to delete all items by logical partition key value.
Read more >Bulk Delete without partition key in Azure Cosmos Db
I notice that you use bulk delete js from github code. That code is working well however there is a key point you...
Read more >UNPKG - @azure/cosmos
36, - Fixed bulk requests which had operations without partitionKey ... Fixes bulk operations with top level partitionKey values that are undefined or...
Read more >Authoring Azure Cosmos DB Stored Procedures with ...
Create Bulk Upload and Bulk Delete Stored Procedures ... replace the placeholder value with the PRIMARY KEY value from your Azure Cosmos DB...
Read more >@azure/cosmos | Yarn - Package Manager
3.13.0 (2021-08-10) ... Bugs Fixed. Fixed bulk requests which had operations without partitionKey specified. ... 3.12.2 (2021-07-21). Features Added. Adopted target ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
that’s right and needs resolving. I’ll reopen this issue and mark as bug since it’s not only erroneous documentation (and in fact, we may want
undefined
to just work the same way as{}
)Intended to close this as we’ve released the quality of life fix