southworks / botbuilder-js

JavaScript SDK used to build chat bots for the Microsoft Bot Framework.
MIT License
1 stars 3 forks source link

PartitionKey value must be supplied for this operation. #34

Open Bill7zz opened 5 years ago

Bill7zz commented 5 years ago

Versions

botbuilder 4.3.0 botbuilder-azure 4.3.4 nodejs version v10.14.2 Windows 10 pro v1803

Describe the bug

When performing a delete operation in a partitioned cosmosDB collection, the following error is thrown:

“{  
   “code”:“BadRequest”,
   “message”:   “PartitionKey value must be supplied for this operation.\r\nActivityId:b46cf62e-d77f-4911-97d4-b8e86186a348,
   \r\nRequestStartTime:2019-03   -27   T20:17:05.5558598   Z,
   RequestEndTime:2019-03   -27   T20:17:05.5558598   Z,
   Number of regions attempted:1   \r\n,
   Microsoft.Azure.Documents.Common/2.2.0.0”
}”

To Reproduce

Steps to reproduce the behavior:

  1. Install the AzureCosmoDb emulator

  2. Create a partitioned collection and insert a new document (Sample image below)

2.1 Use the following information to create a new Cosmos Database in the emulator:

Database name: bot-cosmos-DB
Collection name: bot-collection
PartitionKey: /city

2.2 Add a new document using the following information

{
    "id": "001",
    "name": "contoso",
    "city": "EEUU"
}
  1. Use the echobot-with-counter

  2. Connect the bot with the CosmosDb created

    const policyConfigurator = (policy) => policy.DisableSSLVerification = true;
    const getSettings = () => ({
    serviceEndpoint: 'https://localhost:8081',
    authKey: 'C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==',
    databaseId: 'bot-cosmos-db',
    collectionId: 'bot-collection'
    });
  3. Update the code to attempt to delete the document 5.1 Insert the next code in the onTurn method of the echoBot class

    const storage = new CosmosDbStorage(getSettings(), policyConfigurator);
    
        if (turnContext.activity.type === ActivityTypes.Message) {
    
            try {
                await storage.delete([turnContext.activity.text]);     
            } catch (ex) {
                await turnContext.sendActivity(`Error message when trying to delete in cosmos DB storage`);
                await turnContext.sendActivity(`"${ex.body}"`);
            }
    
        } else {
            // Generic handler for all other activity types.
            await turnContext.sendActivity(`insert the document id to delete`);
        }
        // Save state changes
        await this.conversationState.saveChanges(turnContext);
    }
  4. Run the bot.

    • Insert the document id of the document created before. (sample imagen below)

Expected behavior

Delete the document successfully

Screenshots

The partitioned collection image

After, the following result was found. image

Additional context

gasper-az commented 5 years ago

Reminder: Don't forget to add the related MS PR (# 1537) when promoting to MS

gasper-az commented 5 years ago

LGTM

Aliandi commented 5 years ago

Also, for the subitems, dont use a bullet, use a 1.1 format Something like 1. 1.1. 1.2.