microsoft / vscode-azurefunctions

Azure Functions extension for VS Code
https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-azurefunctions
MIT License
291 stars 132 forks source link

Template for CosmosDB trigger doesn't work with extension bundle version 4 #4212

Open alexweininger opened 1 month ago

alexweininger commented 1 month ago

Code for CosmosDB trigger doesn't work with extension bundle version 4

To reproduce: Create a new TypeScript functions project (I haven't checked if this repros for JS, but I assume yes) that uses the v4 model. Add a CosmosDB trigger. Once added, the code will contain:

app.cosmosDB('cosmosDBTrigger1', {
    connectionStringSetting: 'jokesapiv2_DOCUMENTDB',
    databaseName: 'jokes',
    collectionName: 'jokes',
    createLeaseCollectionIfNotExists: true,
    handler: cosmosDBTrigger1
});

My extension bundle in the host.json is:

  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[4.*, 5.0.0)"
  }

When run, the project will give this error: "The 'cosmosDBTrigger1' function is in error: Unable to configure binding 'cosmosDBTrigger0fe012de42' of type 'cosmosDBTrigger'. This may indicate invalid function.json properties. Can't figure out which ctor to call."

If you change the properties inside the function trigger code to the following, it works.

app.cosmosDB('cosmosDBTrigger1', {
    connection: 'jokesapiv2_DOCUMENTDB',
    databaseName: 'jokes',
    containerName: 'jokes',
    createLeaseContainerIfNotExists: true,
    handler: getJokeFromDb,
});
alexweininger commented 1 month ago

This is happening because the properties in the template are for extension bundle v3, but I'm using extension bundle v4. This documentation sort of explains this: https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-cosmosdb-v2-trigger?tabs=python-v2%2Cisolated-process%2Cextensionv4%2Cnodejs-v4&pivots=programming-language-javascript