fix: 模板配置字段非dict类型崩溃防护 (bool/str/int) #1384

Merged
xiaoxia merged 2 commits from fix/bool-config-crash into develop 2026-08-15 23:50:43 +08:00
Owner

问题

用户在预览/正式渲染时 Worker 崩溃:bool object has no attribute get

根因:模板表 title_config/subtitle_config/bgm_config 字段可能存储了非 dict 值(如 boolean True),加载后直接传入渲染链路,导致 .get() 调用崩溃。

修复

generation.py(3处)

  • _load_template_plan_config:模板加载时对 3 个 config 字段加 isinstance(dict) 防护
  • _render_video_with_audio custom_title 处理:解析前检查类型
  • voice_ids 注入 subtitle_cfg:加 isinstance 防护

unified_render_service.py(3处)

  • _maybe_generate_ass:title_cfg 和 subtitle_cfg 加 isinstance 防护
  • 第795行 subtitle_cfg:同样防护

测试

  • 新增 test_bool_config_defense.py(10个测试),覆盖 bool/str/int/list/None/混合场景
## 问题 用户在预览/正式渲染时 Worker 崩溃:bool object has no attribute get 根因:模板表 title_config/subtitle_config/bgm_config 字段可能存储了非 dict 值(如 boolean True),加载后直接传入渲染链路,导致 .get() 调用崩溃。 ## 修复 ### generation.py(3处) - _load_template_plan_config:模板加载时对 3 个 config 字段加 isinstance(dict) 防护 - _render_video_with_audio custom_title 处理:解析前检查类型 - voice_ids 注入 subtitle_cfg:加 isinstance 防护 ### unified_render_service.py(3处) - _maybe_generate_ass:title_cfg 和 subtitle_cfg 加 isinstance 防护 - 第795行 subtitle_cfg:同样防护 ### 测试 - 新增 test_bool_config_defense.py(10个测试),覆盖 bool/str/int/list/None/混合场景
xiaoxia added 1 commit 2026-08-15 23:38:20 +08:00
fix: guard against non-dict template config fields (bool/str/int crash)
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 36s
CI/CD Pipeline / Frontend Lint (pull_request) Has been skipped
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / PR Build Web Image (pull_request) Has been skipped
Preview Deploy / Deploy Preview Environment (pull_request) Failing after 1m14s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 1m25s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 1m35s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 2m10s
AI Code Review / AI Code Review (pull_request) Successful in 2m18s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 2m51s
CI/CD Pipeline / Validate - Code Quality (pull_request) Has been cancelled
CI/CD Pipeline / Integration Tests (pull_request) Has been cancelled
CI/CD Pipeline / PR Build API Image (pull_request) Has been cancelled
CI/CD Pipeline / PR Build Worker Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Production API Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Production Web Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been cancelled
CI/CD Pipeline / Deploy Production (pull_request) Has been cancelled
CI/CD Pipeline / Production Browser E2E (pull_request) Has been cancelled
CI/CD Pipeline / Canary Release to Production (pull_request) Has been cancelled
CI/CD Pipeline / CI Gate (pull_request) Has been cancelled
PR Automation / Auto Approve on CI Green (pull_request) Has been cancelled
77a606bfd4
Root cause: templates table title_config/subtitle_config/bgm_config
may store non-dict values (e.g. boolean True), causing
"bool object has no attribute get" crash in render pipeline.

Fixes:
- generation.py: _load_template_plan_config — isinstance check
  for all 3 config fields (title/subtitle/bgm)
- generation.py: _render_video_with_audio — isinstance check
  for custom_title and subtitle_cfg in voice_ids injection
- unified_render_service.py: _maybe_generate_ass — isinstance
  check for title_cfg and subtitle_cfg (2 call sites)
- 10 new unit tests in test_bool_config_defense.py

Refs: user-reported crash in preview/formal rendering
auto-approve-bot added 1 commit 2026-08-15 23:42:07 +08:00
style: auto-format with black + isort + prettier [skip ci-format-check]
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 31s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / Frontend Lint (pull_request) Has been skipped
CI/CD Pipeline / PR Build Web Image (pull_request) Has been skipped
Preview Deploy / Deploy Preview Environment (pull_request) Failing after 47s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 1m26s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 1m34s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 1m58s
AI Code Review / AI Code Review (pull_request) Successful in 2m3s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 2m27s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 2m30s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 2m30s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 3m29s
CI/CD Pipeline / Validate - Code Quality (pull_request) Successful in 4m54s
CI/CD Pipeline / Build Production API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Canary Release to Production (pull_request) Has been skipped
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / Integration Tests (pull_request) Successful in 1m51s
CI/CD Pipeline / CI Gate (pull_request) Successful in 6s
ACR Cleanup / ACR Image Cleanup (pull_request_target) Successful in 45s
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 55s
9bbccec3a0
Collaborator

代码审查结果 - PR #1384

⚠️ 问题(0个需要修改)

💡 建议(0个可选)


格式检查通过 | 逻辑审查通过 | 性能无恙


🤖 由 AI 代码审查机器人自动生成 | 2026-08-15 15:44:11 | 模型:

## 代码审查结果 - PR #1384 ### ⚠️ 问题(0个需要修改) 无 ### 💡 建议(0个可选) 无 --- ✅ 格式检查通过 | ✅ 逻辑审查通过 | ✅ 性能无恙 --- <sub>🤖 由 AI 代码审查机器人自动生成 | 2026-08-15 15:44:11 | 模型: </sub> <!-- AI_CODE_REVIEW_AUTO_COMMENT -->
auto-approve-bot approved these changes 2026-08-15 23:50:34 +08:00
auto-approve-bot left a comment
Collaborator

CI全绿,自动审批通过。

CI全绿,自动审批通过。
auto-approve-bot approved these changes 2026-08-15 23:50:34 +08:00
auto-approve-bot left a comment
Collaborator

CI全绿,自动审批通过。

CI全绿,自动审批通过。
xiaoxia merged commit 74e2bdf914 into develop 2026-08-15 23:50:43 +08:00

🗑️ 预览环境已清理

PR #1384 已关闭或合并,对应的预览环境已被清理。

如有需要,可以重新打开 PR 来重新生成预览环境。

🗑️ **预览环境已清理** PR #1384 已关闭或合并,对应的预览环境已被清理。 > 如有需要,可以重新打开 PR 来重新生成预览环境。
Sign in to join this conversation.