How to fix cosmos DB updating issue via Python SDK ?

Aditya Kshirsagar 15 Reputation points

Here's a brief description of my problem :

  • I have few containers under one cosmos db and I'm using azure durable functions to update contents of each containers via Python SDK
  • The status returned by cosmos DB updater is 200 but sometimes the particular record's content on cosmos DB is not getting updated ! (But this works well when I clean-up data from cosmos DB and try again)
  • I have 5 containers under one cosmos DB and each of them have been set to 400 RUs
Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,471 questions
{count} votes

1 answer

Sort by: Most helpful
  1. ShaktiSingh-MSFT 14,081 Reputation points Microsoft Employee

    Aditya Kshirsagar

    Welcome to Microsoft Q&A forum and thanks for using Azure Services.

    As I understand, you are having update issue via Python SDK into Azure Cosmos DB containers records.

    Could you please share the sample code used?

    Also note that when you are using Unique Keys, the check is related to having 2 different documents with the same Unique Key value. The Cosmos DB output binding will try to do an Upsert operation, so if the document already exists, it will try to update it, if not, create it. This error should appear if you are trying to insert a document with different id, but same Unique Key than another existing document.

    Whenever you want to update the record if already existing in cosmosDB from Azure trigger function, below points should be taken care.

    1. Check for the element named id existing in DB collection for a Unique key
    2. The id should be same for the data which is updating for a Unique key while upserting.

    If the element id is not same then, while upserting cosmos will assign a new value for that element and we will have 2 entry for a Unique key with different ids and throw the above error.

    Additionally, check the Consistency Level, Partition Key, Retry Policy and Logs to help in troubleshooting.

    Awaiting your reply if above helps else we will continue to engage on the question.


    0 comments No comments