Search code examples
c#azureexceptionazure-functionsproduction

FunctionInvocationException when Azure function is called


I'm having an issue with my Azure function. The function cannot startup because a FunctionInvocationException is being thrown each time.

The inner exception being an InvalidOperationException with the below message:

PartitionKey must be supplied for this operation

I have two bindings in my function that connect to a Document DB, one is an in binding that retrieves a specific document from a collection, and the other is an out binding used for auditing.

These both work fine in my dev, qa, and uat environments it is only the production environment that is having an issue. Both collections (for the settings and the auditing) were created without a partition key, the same as every environment.

System.InvalidOperationException: at Microsoft.Azure.Documents.Client.DocumentClient+d__347.MoveNext (Microsoft.Azure.Documents.Client, Version=1.11.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)

Any ideas?

I've tried deleting and remaking the audit collection but that didn't work. I don't get why the other environments are fine, but this one isn't.

Edit:

The function.json

{
  "scriptFile": "..\\bin\\Cso.Notification.Function.dll",
  "entryPoint": "Cso.Notification.Function.Program.Run",
  "disabled": false,
  "bindings": [
    {
      "type": "httpTrigger",
      "direction": "in",
      "webHookType": "genericJson",
      "name": "request",
      "methods": [
        "post"
      ]
    },
    {
      "type": "documentDB",
      "name": "subscriberSettings",
      "databaseName": "CSO",
      "collectionName": "Settings",
      "id": "SubscriberSettings",
      "connection": "CsoDocDb",
      "direction": "in"
    },
    {
      "type": "http",
      "direction": "out",
      "name": "res"
    },
    {
      "type": "documentDB",
      "name": "collector",
      "databaseName": "CSO",
      "collectionName": "AuditJSON",
      "connection": "CsoDocDb",
      "direction": "out"
    }
  ]
}

Solution

  • I've found an answer. One of the documents we were querying for an initial value (SubscriberSettings) was incorrectly setup with a PartitionKey.

    Deleting the collection and remaking it without a partition key did the trick.