Closed vijaystroup closed 5 months ago
Thanks for reporting will check and update.share the func invocationid,timestamp ,region etc.
The error was not caused by an invocation of the function.
Upon starting the dev server: func start
, all my functions are listed except this cosmos_trigger.
Then shortly after the list without any invocations to any of the functions it logs an error as indicated in the Actual behavior section.
can you share which doc you use..
Hi @vijaystroup please use the blueprint for your function app. I checked and its working fine.
please see the below code.
.
Still getting the same error:
import logging
import os
import azure.functions as func
bp = func.Blueprint()
@bp.cosmos_db_trigger(
arg_name='documents',
connection='COSMOS_CONNECTION_STRING',
database_name=os.environ['COSMOS_DATABASE'],
container_name=os.environ['COSMOS_CONTAINER'],
create_lease_container_if_not_exists=True,
lease_container_name='lease',
)
def cosmos_trigger(documents: func.DocumentList) -> str:
if documents:
logging.info('Document id: %s', documents[0]['id'])
[2024-01-12T20:43:11.211Z] The 'cosmos_trigger' function is in error: Unable to configure binding 'documents' of type 'cosmosDBTrigger'. This may indicate invalid function.json properties. Can't figure out which ctor to call.
The documentation for lase containers located here do not show an example of "the lease container automatically with the Azure Functions trigger". I'm not 100% sure how the lease container works besides keeping the db in sync with multiple instances of functions, so perhaps I am not setting something up correctly. It should be noted, the code above is the only thing that I changed, I did not manually create a lease container as from the docs it said it would automatically create one.
please follow the doc as in local setting file also have to be maintain "LeaseContainerName":"leases", "CreateLeaseContainerIfNotExists" :true this two props. Try to add the missing details in your local.settings.json file like cosmos DB connection string and the database name and the collection name which you are referring.then it works.
Still same error on start up: The 'cosmos_trigger' function is in error: Unable to configure binding 'documents' of type 'cosmosDBTrigger'. This may indicate invalid function.json properties. Can't figure out which ctor to call.
I do not have to have manually created a lease container correct?
Here I make sure the db, container, and lease names are actually filled in and I do have COSMOS_CONNECTION_STRING set in my local.settings.json file.
The docs indicate that only the connection
argument needs the key name whereas the other arguments need the actual value rather than the key name.
Hi @vijaystroup
No, you don't have to manually create a lease container. create_lease_container_if_not_exists=True
will handle that for you. You can verify that the container exists by checking your CosmosDB database. Also, if one of your resources doesn't exist a 404 error will be thrown at start up.
In your host.json file, what version
for extensionBundle
are you using? I was able to replicate the issue using [3.*, 4.0.0)
, but the function worked properly with [4.*, 5.0.0)
. If you aren't using [4.*, 5.0.0)
, can you try changing to that and see if the issue still occurs?
Hi @vijaystroup
No, you don't have to manually create a lease container.
create_lease_container_if_not_exists=True
will handle that for you. You can verify that the container exists by checking your CosmosDB database. Also, if one of your resources doesn't exist a 404 error will be thrown at start up.In your host.json file, what
version
forextensionBundle
are you using? I was able to replicate the issue using[3.*, 4.0.0)
, but the function worked properly with[4.*, 5.0.0)
. If you aren't using[4.*, 5.0.0)
, can you try changing to that and see if the issue still occurs?
That was it! Thank you.
Investigative information
Repro steps
Expected behavior
Upon insertion of a new document into the container:
Actual behavior
Error on startup:
Known workarounds
Not tested but from looking at other issues, perhaps adding the binding connection information in a
functions.json
file for the specific function would yield the correct results, but other documentation suggests functions.json is for the v1 programming model, not v2.Contents of the requirements.txt file: