question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[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

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:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
zfostercommented, Sep 23, 2020

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 {})

0reactions
zfostercommented, Nov 6, 2020

Intended to close this as we’ve released the quality of life fix

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found