From 5f852140a96d2edf55402b8509750273f4bed2c0 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Tue, 17 Mar 2026 16:59:59 +0800 Subject: [PATCH] bugfix --- dagflow/dagflow.py | 56 +++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/dagflow/dagflow.py b/dagflow/dagflow.py index ac646be..54abe97 100644 --- a/dagflow/dagflow.py +++ b/dagflow/dagflow.py @@ -24,33 +24,33 @@ aeval = Interpreter() # 2. 在你的 node_transfer 或条件判断逻辑中 def safe_eval_condition(cond_str, ctx_dict): - """ - 安全地评估条件表达式 - Args: - cond_str: 表达式字符串,例如 "ctx['age'] > 18 and ctx['score'] >= 60" - ctx_dict: 上下文数据字典 - Returns: None 错误或的确是None - 其他: 表达式结果 - """ - try: - # 将 ctx 注入到 asteval 的符号表中 - aeval.symtable['ctx'] = ctx_dict + """ + 安全地评估条件表达式 + Args: + cond_str: 表达式字符串,例如 "ctx['age'] > 18 and ctx['score'] >= 60" + ctx_dict: 上下文数据字典 + Returns: None 错误或的确是None + 其他: 表达式结果 + """ + try: + # 将 ctx 注入到 asteval 的符号表中 + aeval.symtable['ctx'] = ctx_dict - # 执行表达式 - # mode='eval' 表示只允许单个表达式,不允许语句(如赋值、import) - result = aeval(cond_str, mode='eval') + # 执行表达式 + # mode='eval' 表示只允许单个表达式,不允许语句(如赋值、import) + result = aeval(cond_str, mode='eval') - # 检查是否有语法错误或运行时错误 - if aeval.error: - print(f"asteval Error: {aeval.error}") - return False + # 检查是否有语法错误或运行时错误 + if aeval.error: + print(f"asteval Error: {aeval.error}") + return False - return bool(result) + return bool(result) - except Exception as e: - # asteval 通常很安全,但以防万一 - print(f"Eval Exception: {e}") - return False + except Exception as e: + # asteval 通常很安全,但以防万一 + print(f"Eval Exception: {e}") + return False # --------------------------------------------------------------------- # Table definitions @@ -527,11 +527,11 @@ where instance_id=${instance_id}$ async def task_error_callback(self, ne_id, errmsg): env = Server() async with get_sor_context(env, 'dagflow') as sor: - recs = await sor.R('node_execution', {'id': ne_id}) - if not recs: - debug(f'{ne_id=} 没找到node_execution记录') - return - ne = recs[0] + recs = await sor.R('node_execution', {'id': ne_id}) + if not recs: + debug(f'{ne_id=} 没找到node_execution记录') + return + ne = recs[0] ne.status = 'failed', ne.output = errmsg await sor.U('node_execution', ne)