fix(定时任务): 模板子页面空内容回退原数据,避免子页面显示不全

- 引擎 merge_with_reference:按顶层键(=子页面)逐一合并,转换结果里没抽到有效内容的
  子页面/字段回退模板原有数据(_has_content/_merge_fill 递归,列表/标量整体保留,
  字典逐键回退空分支);整体为空等价于返回模板默认数据
- _run_html_template_reference:描述与任务prompt都为空→直接用原数据不检索;转换成功后
  对结果做 merge_with_reference 补空子页面
- _run_template_fill_attempt 同样套用 merge,空子页面一致回退
- 测试覆盖 _has_content/merge 各场景 + 端到端空子页面回退/空描述用原数据

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
董宏凯andClaude Opus 4.8 committed 2026-06-24 12:20:12 +08:00
1 parent ba885ca201
commit 7d9a0637ca
3 files changed
+69 -4

No files matched your search

@@ -1585,6 +1585,23 @@ class ScheduledTaskService:
used_default=True,
)
# 用户的描述与任务 prompt 都为空 → 不检索/不转换,直接用模板原有数据。
prompt = str(task.get("prompt") or "").strip()
description = str(task.get("description") or "").strip()
if not prompt and not description:
data_obj = template_fill.reference_data(tpl_id)
return await self._finalize_template_html(
task,
spec=spec,
template_id=tpl_id,
html=template_fill.fill_template(tpl_id, data_obj, update_date=scheduled_for.astimezone(ZoneInfo(task.get("timezone") or "UTC")).date()),
run_id=run_id,
scheduled_for=scheduled_for,
content=f"未提供描述,已用模板「{spec.name}」原有数据(含全部子页面)",
source_chars=0,
used_default=True,
)
# 可转换模板:检索真实数据(复用 gather) → 转换成模板 DATA → 填进真模板。
data_text, _files = await self._gather_html_data(
task, runtime_thread_id=runtime_thread_id, scheduled_for=scheduled_for, run_id=run_id
@@ -1597,10 +1614,12 @@ class ScheduledTaskService:
used_default = True
else:
try:
data_obj = await self._convert_to_template_data(
converted = await self._convert_to_template_data(
tpl_id, source, model_name=model_name, soul=None, run_id=run_id
)
content = f"已检索数据并套用模板「{spec.name}」(含全部子页面)"
# 子页面没抽到有效内容的,回退模板原有数据,避免子页面空白。
data_obj = template_fill.merge_with_reference(tpl_id, converted)
content = f"已检索数据并套用模板「{spec.name}」(空子页面回退原数据,含全部子页面)"
except TemplateFillError:
logger.warning("模板参考转换失败,回退默认数据 run=%s tpl=%s", run_id, tpl_id, exc_info=True)
data_obj = template_fill.reference_data(tpl_id)
@@ -1685,9 +1704,11 @@ class ScheduledTaskService:
except Exception:
model_name = None
data_obj = await self._convert_to_template_data(
converted = await self._convert_to_template_data(
template_id, source, model_name=model_name, soul=soul, run_id=run_id
)
# 子页面没抽到有效内容的,回退模板原有数据,避免子页面空白。
data_obj = template_fill.merge_with_reference(template_id, converted)
content = f"已根据源数据填充模板「{spec.name}」生成页面"
used_default = False