返回 Bug 清单
BUG-0210project-27已修复backend-logic

dict.get(key, default) 不 null-safe —— 快照含 null 时整条流水线崩溃 13 天

发现:2026-09-30验证:2026-10-09置信度:98%

症状

工作区健康扫描生成器运行后无输出/崩溃;而看板仍显示 healthy:true,数据停滞 13 天(09-17 之后的快照带有 null 项,从 09-25 起每次运行都崩)。

根因

代码写 prev_h = prev.get("health", 100)。dict.get 的默认值【只在键不存在时生效】;键存在但值为 None 时返回 None。于是 drop = prev_h - today_h ⇒ None - int ⇒ TypeError ⇒ 整个生成器崩溃。

修复方案

1) 必须显式处理 null:prev_h = prev.get('health'); if prev_h is None or today_h is None: 跳过比较; 2) 更根本:生成器的顶层要有 try/except + 非零退出码,并让调用方【检查退出码】—— 本次崩溃之所以静默 13 天,是因为调用方只看输出文件是否存在; 3) 数据文件里 null 与『键缺失』语义应统一约定。

检测命令

grep -rnE '\.get\([^)]+, *[0-9]+\)' <scripts> | head

修复命令

python - <<'EOF'
# 改为 null-safe
prev_h = prev.get('health')
today_h = today.get('health')
if prev_h is None or today_h is None:
    continue
drop = prev_h - today_h
EOF

错误签名

TypeError: unsupported operand type(s) for -: 'NoneType' and 'int'

技术信息

来源项目

project-27

标签

python, dict-get, null-safety, silent-failure, data-pipeline