Azure Durable Functions报错:模块无BluePrint属性,求运行解决方案
解决AttributeError: module 'azure.durable_functions' has no attribute 'BluePrint'
问题本质:
azure.durable_functions模块并未提供BluePrint类,你错误地尝试从Durable模块中获取蓝图类。实现Durable Functions的跨文件代码拆分,需结合Azure Functions标准Blueprint与Durable装饰器。正确实现方案:
- 在拆分的子文件(如
chat_bp.py)中导入标准蓝图和Durable模块:from azure.functions import Blueprint import azure.durable_functions as df bp_chat = Blueprint() - 在蓝图上定义Durable相关函数(活动/编排器):
# 活动函数示例 @bp_chat.activity_trigger(input_name="input_data") def chat_process_activity(input_data: dict): return f"Processed data: {input_data}" # 编排器函数示例 @bp_chat.orchestration_trigger(context_name="orchestration_context") def chat_flow_orchestrator(orchestration_context: df.DurableOrchestrationContext): input_data = orchestration_context.get_input() activity_result = yield orchestration_context.call_activity("chat_process_activity", input_data) return activity_result - 在
function_app.py中导入并注册蓝图:import azure.durable_functions as df from chat_bp import bp_chat # 初始化Durable应用 app = df.DurableApp(http_auth_level="anonymous") # 注册蓝图 app.register_blueprint(bp_chat) # 添加HTTP触发的客户端启动函数(可选) @app.route(route="start-orchestrator/{functionName}") @app.durable_client_input(client_name="durable_client") def http_start_orchestrator(req, durable_client): function_name = req.route_params.get('functionName') instance_id = durable_client.start_new(function_name, None, req.get_json()) return durable_client.create_check_status_response(req, instance_id)
- 在拆分的子文件(如
版本兼容检查:确保依赖包版本匹配,推荐安装/升级到:
pip install --upgrade azure-functions>=1.17.0 azure-durable-functions>=1.2.6
内容的提问来源于stack exchange,提问作者Ádám Molnár
相关产品推荐
相关产品推荐

