vscode-azurefunctions icon indicating copy to clipboard operation
vscode-azurefunctions copied to clipboard

Adding CosmosDB Output binding through the wizard creates invalid json

Open jpomfret opened this issue 2 years ago • 1 comments

Version of VS Code - 1.67.2 Your operating system - Windows 11 Version of the relevant VS Code extension - Azure Functions v1.7.2 Reproducible steps (1... 2... 3...) that cause the issue

  • create a function project

  • add a blob storage trigger

  • add a cosmosdb output binding

    • follow the prompts but leave partitionkey and collectionThrouthput as 'undefined'
  • try and run the function locally with F5

    What you expected to see, versus what you actually saw You get this error in the terminal: image

  • If instead of running locally you deploy it to Azure, the function just doesn't trigger and I couldn't find errors anywhere to explain why

function.json file after adding the CosmosDB binding through the wizard:

{
  "bindings": [
    {
      "name": "InputBlob",
      "type": "blobTrigger",
      "direction": "in",
      "path": "source2/{name}",
      "connection": "storagefundemo7_STORAGE"
    },
    {
      "type": "cosmosDB",
      "direction": "out",
      "name": "outputDocument",
      "databaseName": "grillenDb",
      "collectionName": "data",
      "createIfNotExists": false,
      "connectionStringSetting": "cosmosdbfunctiondemo_DOCUMENTDB",
      "partitionKey": "undefined",
      "collectionThroughput": "undefined"
    }
  ]
}

To fix the issue I had to remove these two keys (and the preceding comma) and redeploy the function to Azure.

      "partitionKey": "undefined",
      "collectionThroughput": "undefined"

jpomfret avatar May 31 '22 16:05 jpomfret

When writing the json file, we shouldn't write properties with values of "undefined".

alexweininger avatar Jun 09 '22 22:06 alexweininger

Thank you @motm32 I will test it out soon! 😄

jpomfret avatar Oct 31 '22 15:10 jpomfret