You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure Durable Function Python本地测试报错:HistoryEvent缺少必填参数

本地调试Azure Durable Function时出现参数命名不匹配错误

问题场景

我按照官方文档搭建首个Azure Durable Function,代码如下:

import azure.functions as func
import azure.durable_functions as df
from src.main import engine_main
from datetime import datetime, timedelta

myApp = df.DFApp(http_auth_level=func.AuthLevel.ANONYMOUS)

@myApp.route(route="orchestrators/{functionName}")
@myApp.durable_client_input(client_name="client")
async def http_start(req: func.HttpRequest, client):
    function_name = req.route_params.get("functionName")
    instance_id = await client.start_new(function_name)
    response = client.create_check_status_response(req, instance_id)
return response

@myApp.orchestration_trigger(context_name="context")
def hello_orchestrator(context):
    result1 = yield context.call_activity("hello", "Seattle") 
    result2 = yield context.call_activity("hello", "Tokyo")
    result3 = yield context.call_activity("hello", "London")
    return [result1, result2, result]

@myApp.activity_trigger(input_name="city")
def hello(city: str):
    return city

报错信息

函数启动后,通过浏览器请求时VS调试窗口报错:

'hello_orchestrator (Orchestrator)' failed with an error. Reason: System.AggregateException: One or more errors occurred. (Result: Failure
Exception: TypeError: HistoryEvent.init() missing 4 required positional arguments: 'EventType', 'EventId', 'IsPlayed', and 'Timestamp'

错误堆栈指向:

.venv\lib\site-packages\azure\durable_functions\models\DurableOrchestrationContext.py", line 50, in
self._histories: List[HistoryEvent] = [HistoryEvent(**he) for he in history]

问题排查

经排查,问题出在Durable Function库的HistoryEvent.py文件中:其构造函数要求传入4个Pascal命名的参数(EventType、EventId、IsPlayed、Timestamp),但本地调试时从队列获取的JSON数据中是驼峰命名的参数(eventType、eventId、isPlayed、timeStamp)。

已尝试的解决方法

  • 将代码部署到Azure云端,可正常运行
  • 切换到Durable Function Python V1版本
  • 重新安装所有依赖包
    以上方法均无法解决本地调试的问题。

本地环境版本

  • Windows 11
  • VS Code 1.77.2
  • Azure Function Runtime版本:4.14.0.19631
  • Python:3.10.11(及3.9.13)
  • azure-functions==1.13.3
  • azure-functions-durable==1.2.2

内容的提问来源于stack exchange,提问作者C Shen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 04:52:41