azure-functions - 用于访问字典值的 Azure 函数绑定表达式
问题描述
我正在尝试在 function.json 文件中创建绑定,该文件将根据触发函数的服务总线消息启用 Cosmos DB 文档的输入。
我想在服务总线消息的 UserProperties 字典中使用一个值。文档告诉我,这可用于绑定中:https ://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-service-bus#trigger---message-metadata
但是,当我收到以下错误时,我似乎无法在字典中使用值:
Microsoft.Azure.WebJobs.Host: Invalid template '{UserProperties['MyId']}'. Invalid template expression 'UserProperties['MyId'].
我的 function.json 的内容是:
{
"scriptFile": "__init__.py",
"disabled": false,
"bindings": [
{
"name": "msg",
"type": "serviceBusTrigger",
"direction": "in",
"topicName": "mytopic",
"subscriptionName": "mysubscription",
"connection": "myservicebus_SERVICEBUS"
},
{
"name": "documents",
"type": "cosmosDB",
"databaseName": "Cache",
"collectionName": "ProductVersion",
"id" : "{UserProperties['MyId']}",
"partitionKey": "{UserProperties['MyId']}",
"connectionStringSetting": "mycosmos_COSMOSDB",
"direction": "in"
}
]
}
https://docs.microsoft.com/en-us/azure/azure-functions/functions-triggers-bindings#binding-expressions-and-patterns上的文档说我可以使用点符号来访问对象的属性,但没有提到访问字典值。
我也尝试过双引号"partitionKey": "{UserProperties[\"MyId\"]}"
和点符号"partitionKey": "{UserProperties.MyId}"
,但这些也不起作用。
该函数恰好是用 Python 编写的,但希望这无关紧要。
我做错了什么,还是不支持?
更新 1
我使用时遇到的错误{UserProperties.MyId}
是:
Exception: TypeError: unable to decode incoming TypedData: unsupported combination of TypedData field None and expected binding type serviceBusTrigger
Stack: File "d:\Workspace\MyFunction\.env\lib\site-packages\azure\functions_worker\dispatcher.py", line 250, in _handle__invocation_request
pytype=pb_type_info.pytype)
File "d:\Workspace\MyFunction\.env\lib\site-packages\azure\functions_worker\bindings\meta.py", line 291, in from_incoming_proto
f'unable to decode incoming TypedData: '
所以也许这是 Python 特有的问题?
Update2
无论属性是否为字典,都会发生此错误。main
定义如下所示:
def main(msg: func.ServiceBusMessage, documents: func.DocumentList):
更新 3 当服务总线消息有效负载为空时会发生错误。该问题已报告:https ://github.com/Azure/azure-functions-python-worker/issues/330
解决方案
推荐阅读
- java - 如何以时间戳/日期时间格式在 Scala 中获取当前时间,以便将其存储在 PG 表中
- if-statement - Airtable If 语句输出 NaN
- jquery - 获取最后 4 条记录而不获取 4 条记录数据 laravel
- javascript - 这是 IE 11 中的错误吗?
- r - R ggplot 在 geom_rect 中添加注释
- sql - SQL 查询 User.first_name OR User.last_name OR 两者?
- php - PHP 将文本转换为查询
- javascript - 更新网页以包含被阻止的 iframe,但初始加载工作正常
- zeromq - ZMQ PUB SUB LOST TCP CONNECTION ON PUB 端
- sql - Oracle 查询 where field1=field2 and field2=field1