I have been experimenting with azure functions using python. I have followed the guide found at https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-cosmosdb-v2#http-trigger-look-up-id-from-query-string-python. This works fine, I can query the enpoint using ?id=0
and I get the correct response. Although as soon as I replace the 0 with an id that is not present in my cosmos db in azure it throws a 500. The corresponding javascript example works.
Stack trace:
[9/17/19 5:53:18 PM] Executed 'Functions.HttpReader' (Failed, Id=23f0d832-5d00-4ffc-a5b9-3e20fed1c105)
[9/17/19 5:53:18 PM] System.Private.CoreLib: Exception while executing function: Functions.HttpReader. System.Private.CoreLib: Result: Failure
[9/17/19 5:53:18 PM] Exception: AttributeError: 'NoneType' object has no attribute 'type'
[9/17/19 5:53:18 PM] Stack: File "/usr/local/Cellar/azure-functions-core-tools/2.7.1585/workers/python/deps/azure_functions_worker/dispatcher.py", line 294, in _handle__invocation_request
[9/17/19 5:53:18 PM] pytype=pb_type_info.pytype)
[9/17/19 5:53:18 PM] File "/usr/local/Cellar/azure-functions-core-tools/2.7.1585/workers/python/deps/azure_functions_worker/bindings/meta.py", line 63, in from_incoming_proto
[9/17/19 5:53:18 PM] return binding.decode(datum, trigger_metadata=metadata)
[9/17/19 5:53:18 PM] File "/usr/local/Cellar/azure-functions-core-tools/2.7.1585/workers/python/deps/azure/functions/cosmosdb.py", line 23, in decode
[9/17/19 5:53:18 PM] data_type = data.type
[9/17/19 5:53:18 PM] .
Code:
import logging
import azure.functions as func
def main(req: func.HttpRequest, doc: func.DocumentList) -> func.HttpResponse:
logging.warn('Python HTTP trigger function processed a request.')
if not doc:
return func.HttpResponse(
"Not found",
status_code=404
)
else:
return func.HttpResponse(
body=doc[0].to_json(),
status_code=200
)
function.json:
{
"scriptFile": "__init__.py",
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "$return"
},
{
"type": "cosmosDB",
"name": "doc",
"databaseName": "<my-cosmos>",
"collectionName": "<my-col>",
"connectionStringSetting": "<conn-string>",
"direction": "in",
"id": "{Query.id}"
}
]
}
To me this seems like a bug, but I am feel like I need a sanity check.
So is this a bug? Or have I messed something up?
?id=0
. I am unsure if this gets interpreted as a string or a number as it happens outside of my function. Did I understand your question correctly? @MatiasQuaranta – Gustav Eiman