Azure / azure-functions-core-tools

Command line tools for Azure Functions
MIT License
1.32k stars 435 forks source link

Cosmos DB Trigger was unable to start locally ( Error: PartitionKey value must be supplied for this operation) #930

Closed yokawasa closed 5 years ago

yokawasa commented 5 years ago

Cosmos DB Trigger was unable to start locally. Here is an error mesage

[2018/12/13 2:19:22] The listener for function 'Functions.testCosmosDBTrigger' was unable to start. Microsoft.Azure.DocumentDB.Core: PartitionKey value must be supplied for this operation.

According to the error, PartitionKey isn't supplied but the collection that I configure to use for this function has a partition key.

Environment info

function.json

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "type": "cosmosDBTrigger",
      "name": "documents",
      "direction": "in",
      "leaseCollectionName": "leases",
      "connectionStringSetting": "AzureWebJobsCosmosDBConnectionString",
      "databaseName": "test",
      "collectionName": "test",
      "createLeaseCollectionIfNotExists": true
    }
  ]
}

console output in starting functions:


                  %%%%%%
                 %%%%%%
            @   %%%%%%    @
          @@   %%%%%%      @@
       @@@    %%%%%%%%%%%    @@@
     @@      %%%%%%%%%%        @@
       @@         %%%%       @@
         @@      %%%       @@
           @@    %%      @@
                %%
                %

Azure Functions Core Tools (2.2.32 Commit hash: c5476ae629a0a438d6850e58eae1f5203c896cd6)
Function Runtime Version: 2.0.12165.0
[2018/12/13 2:19:18] Building host: startup suppressed:False, configuration suppressed: False
[2018/12/13 2:19:18] Reading host configuration file '/Users/yoichika/dev/tests/azure/customer/nhk/autoss/functions/host.json'
[2018/12/13 2:19:18] Host configuration file read:
[2018/12/13 2:19:18] {
[2018/12/13 2:19:18]   "version": "2.0"
[2018/12/13 2:19:18] }
[2018/12/13 2:19:18] Initializing Host.
[2018/12/13 2:19:18] Host initialization: ConsecutiveErrors=0, StartupCount=1
[2018/12/13 2:19:18] Starting JobHost
[2018/12/13 2:19:18] Starting Host (HostId=mac2-1772499559, InstanceId=f3b91187-53b9-45fe-bc14-1f657d6876db, Version=2.0.12165.0, ProcessId=12214, AppDomainId=1, InDebugMode=False, InDiagnosticMode=False, FunctionsExtensionVersion=)
[2018/12/13 2:19:18] Loading functions metadata
[2018/12/13 2:19:19] 1 functions loaded
[2018/12/13 2:19:19] Starting language worker process:python  "/usr/local/lib/node_modules/azure-functions-core-tools/bin/workers/python/worker.py" --host 127.0.0.1 --port 61652 --workerId f2f5712f-dae7-4337-bd78-5480b69e95e6 --requestId 013d5b0e-5c99-4fac-8eb3-d4508127be6e --grpcMaxMessageLength 134217728
[2018/12/13 2:19:19] python process with Id=12215 started
[2018/12/13 2:19:19] Generating 1 job function(s)
[2018/12/13 2:19:20] Found the following functions:
[2018/12/13 2:19:20] Host.Functions.testCosmosDBTrigger
[2018/12/13 2:19:20] 
[2018/12/13 2:19:20] Host initialized (1642ms)
[2018/12/13 2:19:22] The listener for function 'Functions.testCosmosDBTrigger' was unable to start.
[2018/12/13 2:19:22] The listener for function 'Functions.testCosmosDBTrigger' was unable to start. Microsoft.Azure.DocumentDB.Core: PartitionKey value must be supplied for this operation.
[2018/12/13 2:19:22] Host started (4234ms)
[2018/12/13 2:19:22] Job host started
Hosting environment: Production
Content root path: /Users/yoichika/dev/tests/azure/customer/nhk/autoss/functions
Now listening on: http://0.0.0.0:7071
Application started. Press Ctrl+C to shut down.
[2018/12/13 2:19:24] Retrying to start listener for function 'Functions.testCosmosDBTrigger' (Attempt 1)
[2018/12/13 2:19:24] The listener for function 'Functions.testCosmosDBTrigger' was unable to start.
[2018/12/13 2:19:24] The listener for function 'Functions.testCosmosDBTrigger' was unable to start. Microsoft.Azure.Documents.ChangeFeedProcessor: Host was already initialized.
[2018/12/13 2:19:28] Retrying to start listener for function 'Functions.testCosmosDBTrigger' (Attempt 2)
[2018/12/13 2:19:28] The listener for function 'Functions.testCosmosDBTrigger' was unable to start.
[2018/12/13 2:19:28] The listener for function 'Functions.testCosmosDBTrigger' was unable to start. Microsoft.Azure.Documents.ChangeFeedProcessor: Host was already initialized.
[2018/12/13 2:19:35] Retrying to start listener for function 'Functions.testCosmosDBTrigger' (Attempt 3)
[2018/12/13 2:19:35] The listener for function 'Functions.testCosmosDBTrigger' was unable to start.
[2018/12/13 2:19:35] The listener for function 'Functions.testCosmosDBTrigger' was unable to start. Microsoft.Azure.Documents.ChangeFeedProcessor: Host was already initialized.
[2018/12/13 2:19:46] Retrying to start listener for function 'Functions.testCosmosDBTrigger' (Attempt 4)
[2018/12/13 2:19:46] The listener for function 'Functions.testCosmosDBTrigger' was unable to start.
[2018/12/13 2:19:46] The listener for function 'Functions.testCosmosDBTrigger' was unable to start. Microsoft.Azure.Documents.ChangeFeedProcessor: Host was already initialized.
[2018/12/13 2:20:03] Retrying to start listener for function 'Functions.testCosmosDBTrigger' (Attempt 5)
[2018/12/13 2:20:03] The listener for function 'Functions.testCosmosDBTrigger' was unable to start.
[2018/12/13 2:20:03] The listener for function 'Functions.testCosmosDBTrigger' was unable to start. Microsoft.Azure.Documents.ChangeFeedProcessor: Host was already initialized.
[2018/12/13 2:20:38] Retrying to start listener for function 'Functions.testCosmosDBTrigger' (Attempt 6)
[2018/12/13 2:20:38] The listener for function 'Functions.testCosmosDBTrigger' was unable to start.
[2018/12/13 2:20:38] The listener for function 'Functions.testCosmosDBTrigger' was unable to start. Microsoft.Azure.Documents.ChangeFeedProcessor: Host was already initialized.
[2018/12/13 2:21:50] Retrying to start listener for function 'Functions.testCosmosDBTrigger' (Attempt 7)
[2018/12/13 2:21:50] The listener for function 'Functions.testCosmosDBTrigger' was unable to start.
[2018/12/13 2:21:50] The listener for function 'Functions.testCosmosDBTrigger' was unable to start. Microsoft.Azure.Documents.ChangeFeedProcessor: Host was already initialized.
[2018/12/13 2:23:47] Retrying to start listener for function 'Functions.testCosmosDBTrigger' (Attempt 8)
[2018/12/13 2:23:47] The listener for function 'Functions.testCosmosDBTrigger' was unable to start.
[2018/12/13 2:23:47] The listener for function 'Functions.testCosmosDBTrigger' was unable to start. Microsoft.Azure.Documents.ChangeFeedProcessor: Host was already initialized.
[2018/12/13 2:25:47] Retrying to start listener for function 'Functions.testCosmosDBTrigger' (Attempt 9)
[2018/12/13 2:25:47] The listener for function 'Functions.testCosmosDBTrigger' was unable to start.
[2018/12/13 2:25:47] The listener for function 'Functions.testCosmosDBTrigger' was unable to start. Microsoft.Azure.Documents.ChangeFeedProcessor: Host was already initialized.
[2018/12/13 2:27:47] Retrying to start listener for function 'Functions.testCosmosDBTrigger' (Attempt 10)
[2018/12/13 2:27:47] The listener for function 'Functions.testCosmosDBTrigger' was unable to start.
[2018/12/13 2:27:47] The listener for function 'Functions.testCosmosDBTrigger' was unable to start. Microsoft.Azure.Documents.ChangeFeedProcessor: Host was already initialized.
[2018/12/13 2:29:47] Retrying to start listener for function 'Functions.testCosmosDBTrigger' (Attempt 11)
[2018/12/13 2:29:47] The listener for function 'Functions.testCosmosDBTrigger' was unable to start.
[2018/12/13 2:29:47] The listener for function 'Functions.testCosmosDBTrigger' was unable to start. Microsoft.Azure.Documents.ChangeFeedProcessor: Host was already initialized.

Cosmos DB

screen shot 2018-12-13 at 11 46 42
essu72 commented 5 years ago

Hit the same when we started a new project today.

Are you using database level scaling? It seems to require partition key to all collections, and as a wild guess based on this:

https://stackoverflow.com/questions/46821204/how-do-i-supply-partitionkey-for-registerobserverfactoryasync-function-in-cosmos

...partitioned lease collection is not supported yet?

At least when I tested with collection level scaling, everything works.

yokawasa commented 5 years ago

@essu72 Thanks for the info! I tried with single-partition lease collection, and I confirmed that it worked. Looks like partitioned lease collection is not supported.

essu72 commented 5 years ago

...and this is not only local dev problem but a generic trigger problem. Next question is - when will it be supported :)

JohnReeson commented 5 years ago

A PR is underway. Issue can be closed as it's not related to the core tools.

yokawasa commented 5 years ago

@JohnReeson Thanks for the info! As advised, let me go ahead to close this issue