fix(edit-flow): 补全 title_config 数据链路,修复编辑流程断裂 #1464

Merged
xiaoxia merged 4 commits from fix/edit-flow-data-chain into develop 2026-08-23 13:55:42 +08:00
Owner

改动

1. Schema 补字段

  • CreateGenerationTaskRequest 新增 title_config: dict | None = None
  • source_edit_plan_id 字段已存在,确认无需重复添加
  • GenerationTaskResponse 新增 title_config 返回

2. 数据库

  • generation_tasks 新增 title_config JSON 列,alembic 057 迁移
  • ORM model / repository mapping 全链路支持

3. 创建任务后回写 plan.config

  • 任务入队成功后,若请求传了 source_edit_plan_id,merge 更新对应 EditPlan.config
  • 写入 generation_task_id 和 title_config,不整体覆盖
  • 回写失败 catch 异常记日志,不影响任务创建

4. Worker 读取 title_config

  • _load_task_info 读取 title_config
  • _render_video 优先使用 title_config 构建标题图层
  • custom_title 作为兜底,逻辑兼容

5. 旧路由标记废弃

  • POST /generate 和 GET /generation-status 加 DEPRECATED 注释
  • 不删除代码,不改动逻辑

兼容性

  • 所有新增字段默认 None/{},不传时行为完全不变
  • 215 个相关单元测试全通过
## 改动 ### 1. Schema 补字段 - CreateGenerationTaskRequest 新增 title_config: dict | None = None - source_edit_plan_id 字段已存在,确认无需重复添加 - GenerationTaskResponse 新增 title_config 返回 ### 2. 数据库 - generation_tasks 新增 title_config JSON 列,alembic 057 迁移 - ORM model / repository mapping 全链路支持 ### 3. 创建任务后回写 plan.config - 任务入队成功后,若请求传了 source_edit_plan_id,merge 更新对应 EditPlan.config - 写入 generation_task_id 和 title_config,不整体覆盖 - 回写失败 catch 异常记日志,不影响任务创建 ### 4. Worker 读取 title_config - _load_task_info 读取 title_config - _render_video 优先使用 title_config 构建标题图层 - custom_title 作为兜底,逻辑兼容 ### 5. 旧路由标记废弃 - POST /generate 和 GET /generation-status 加 DEPRECATED 注释 - 不删除代码,不改动逻辑 ## 兼容性 - 所有新增字段默认 None/{},不传时行为完全不变 - 215 个相关单元测试全通过
xiaoxia added 1 commit 2026-08-23 13:12:59 +08:00
fix(edit-flow): 补全 title_config 数据链路,修复编辑流程断裂
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
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 / 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 32s
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
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 55s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 1m38s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 1m58s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 2m1s
AI Code Review / AI Code Review (pull_request) Failing after 2m15s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 2m29s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 2m1s
CI/CD Pipeline / Validate - Code Quality (pull_request) Has been cancelled
CI/CD Pipeline / Unit Tests (pull_request) Has been cancelled
CI/CD Pipeline / Integration Tests (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
06f68230af
1. Schema: CreateGenerationTaskRequest 增加 title_config(dict|None=None)
2. DB: generation_tasks 新增 title_config JSON 列 (alembic 057)
3. Domain/ORM/Repo/UseCase 全链路透传 title_config
4. API 创建任务成功后,merge 回写 EditPlan.config
   (generation_task_id + title_config),失败不影响主流程
5. Worker 优先使用 title_config 构建标题图层,custom_title 兜底
6. GenerationTaskResponse 返回 title_config
7. 旧路由 /generate 和 /generation-status 标记 DEPRECATED

所有新字段默认 None/{},不传时行为与现在完全一致。

🚀 预览环境已部署

项目 详情
PR号 #1464
预览链接 https://pr-1464.preview.xiaoxiajianji.com
API环境 staging

💡 预览环境使用 staging API 数据,请勿在预览环境中操作重要数据。

🔄 每次提交新代码后预览环境会自动更新。

🗑️ PR 关闭或合并后,预览环境会自动清理。

🚀 **预览环境已部署** | 项目 | 详情 | |------|------| | PR号 | #1464 | | 预览链接 | [https://pr-1464.preview.xiaoxiajianji.com](https://pr-1464.preview.xiaoxiajianji.com) | | API环境 | staging | > 💡 预览环境使用 staging API 数据,请勿在预览环境中操作重要数据。 > > 🔄 每次提交新代码后预览环境会自动更新。 > > 🗑️ PR 关闭或合并后,预览环境会自动清理。
auto-approve-bot added 1 commit 2026-08-23 13:15:42 +08:00
style: auto-format with black + isort + prettier [skip ci-format-check]
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
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 / 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 37s
CI/CD Pipeline / Frontend Lint (pull_request) Has been skipped
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 1m21s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 1m29s
CI/CD Pipeline / PR Build Web Image (pull_request) Has been skipped
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 1m50s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 37s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 2m48s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 2m15s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 3m50s
AI Code Review / AI Code Review (pull_request) Successful in 4m53s
CI/CD Pipeline / Validate - Code Quality (pull_request) Successful in 7m1s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 2m40s
CI/CD Pipeline / Unit Tests (pull_request) Failing after 12m4s
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 / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Canary Release to Production (pull_request) Has been skipped
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / CI Gate (pull_request) Failing after 6s
410f672195
auto-approve-bot approved these changes 2026-08-23 13:25:34 +08:00
auto-approve-bot left a comment
Collaborator

CI全绿,自动审批通过。

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

CI全绿,自动审批通过。

CI全绿,自动审批通过。
xiaoxia added 1 commit 2026-08-23 13:35:10 +08:00
test: 补全 _writeback_edit_plan_config 单测,修复增量覆盖率不足
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 35s
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 / Validate - Type Check (mypy) (pull_request) Successful in 1m39s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 1m40s
CI/CD Pipeline / Frontend Lint (pull_request) Has been skipped
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been skipped
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 1m20s
CI/CD Pipeline / PR Build 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
AI Code Review / AI Code Review (pull_request) Failing after 2m16s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 34s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 2m8s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 1m38s
CI/CD Pipeline / Validate - Code Quality (pull_request) Failing after 4m18s
CI/CD Pipeline / Unit Tests (pull_request) Has been cancelled
CI/CD Pipeline / Integration Tests (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) Successful in 3m17s
817c6fa6a3
新增 9 个单元测试覆盖 generation_tasks.py 增量代码:
- 空 plan_id 直接返回
- plan 不存在 warning + 不 commit
- 正常写入(有/无 title_config)
- config 非 dict 兜底
- DB 异常 rollback + rollback 失败静默
- 空 title_config 不写入
auto-approve-bot added 1 commit 2026-08-23 13:39:30 +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 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 45s
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
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 41s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 1m46s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 1m50s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 1m53s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 2m26s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 1m46s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 3m42s
CI/CD Pipeline / Validate - Code Quality (pull_request) Successful in 5m18s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 3m17s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 10m6s
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 / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Canary Release to Production (pull_request) Has been skipped
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / CI Gate (pull_request) Successful in 6s
ACR Cleanup / ACR Image Cleanup (pull_request_target) Waiting to run
AI Code Review / AI Code Review (pull_request) Waiting for AI Code Review to complete
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 1m13s
0b000f96a6
Collaborator

【阻塞级判定】

  • 是否存在阻塞级问题:是
  • 阻塞级问题数量:1 个

📊 审查概览

  • 整体评价:需修改
  • 建议级问题数量:1 个

🔴 阻塞级问题(必须修复)

  1. [apps/api/app/api/routes/generation_tasks.py: 371-379] 批量生成任务时 EditPlan 关联数据丢失风险
    • 问题类型:逻辑bug
    • 问题描述:在 create_generation_task 函数中,针对批量创建任务(request.count > 1)的场景,代码在循环内部对同一个 source_edit_plan_id 调用 _writeback_edit_plan_config。该函数会直接覆盖 EditPlan.config 中的 generation_task_id 字段。这意味着当批量生成多个任务时,EditPlan 最终只会关联到最后一个生成的任务 ID,前序任务的关联信息会被覆盖丢失。如果业务依赖 EditPlan 反向查询生成的任务,这将导致数据不一致。
    • 修改建议:调整回写逻辑。如果是批量生成,应考虑将 generation_task_id 存储为数组,或者仅在生成第一个任务时回写,或者确认业务逻辑上只需关联最后一个任务(但通常批量任务需要保留所有关联)。建议修改 _writeback_edit_plan_config 逻辑,或者仅在循环结束后统一处理关联。

💡 改进建议(不阻塞合并)

  1. [packages/adapters/sqlalchemy_impl/models.py: 301] SQLAlchemy 模型存在可变默认参数风险
    • 具体内容:title_config = Column(JSON, nullable=False, default=dict) 使用了 default=dict。在 Python 中,这会导致所有未显式设置该字段的新实例共享同一个 dict 对象引用。虽然在 SQLAlchemy 中通常通过 server_default 或 flush 机制规避了部分风险,但在 Python 对象层面操作时仍可能导致脏数据污染。建议改为 default={} 或使用 default_factory(如果框架支持),或者依赖 server_default 并移除 Python 侧的 default=dict

良好实践

  • 防御性编程:在 _writeback_edit_plan_config 中对 plan_model.config 进行了类型检查(isinstance(plan_model.config, dict)),防止因旧数据格式问题导致崩溃。
  • 异常处理_writeback_edit_plan_config 捕获了所有异常并回滚事务,确保回写失败不影响主流程(任务创建)。
  • 数据兼容:在 Worker 渲染逻辑中,同时处理了新的 title_config 和旧的 custom_title,并做了字段名归一化(font_size -> size),保证了平滑过渡和向后兼容。
  • 测试覆盖:新增了 test_writeback_edit_plan_config.py,覆盖了空值、异常、回滚等多种边界情况。

🤖 由 AI 代码审查机器人自动生成 | 2026-08-23 05:41:09 | 模型:

### 【阻塞级判定】 - 是否存在阻塞级问题:是 - 阻塞级问题数量:1 个 ### 📊 审查概览 - 整体评价:需修改 - 建议级问题数量:1 个 ### 🔴 阻塞级问题(必须修复) 1. **[apps/api/app/api/routes/generation_tasks.py: 371-379] 批量生成任务时 EditPlan 关联数据丢失风险** - 问题类型:逻辑bug - 问题描述:在 `create_generation_task` 函数中,针对批量创建任务(`request.count > 1`)的场景,代码在循环内部对同一个 `source_edit_plan_id` 调用 `_writeback_edit_plan_config`。该函数会直接覆盖 `EditPlan.config` 中的 `generation_task_id` 字段。这意味着当批量生成多个任务时,`EditPlan` 最终只会关联到最后一个生成的任务 ID,前序任务的关联信息会被覆盖丢失。如果业务依赖 `EditPlan` 反向查询生成的任务,这将导致数据不一致。 - 修改建议:调整回写逻辑。如果是批量生成,应考虑将 `generation_task_id` 存储为数组,或者仅在生成第一个任务时回写,或者确认业务逻辑上只需关联最后一个任务(但通常批量任务需要保留所有关联)。建议修改 `_writeback_edit_plan_config` 逻辑,或者仅在循环结束后统一处理关联。 ### 💡 改进建议(不阻塞合并) 1. **[packages/adapters/sqlalchemy_impl/models.py: 301] SQLAlchemy 模型存在可变默认参数风险** - 具体内容:`title_config = Column(JSON, nullable=False, default=dict)` 使用了 `default=dict`。在 Python 中,这会导致所有未显式设置该字段的新实例共享同一个 `dict` 对象引用。虽然在 SQLAlchemy 中通常通过 `server_default` 或 flush 机制规避了部分风险,但在 Python 对象层面操作时仍可能导致脏数据污染。建议改为 `default={}` 或使用 `default_factory`(如果框架支持),或者依赖 `server_default` 并移除 Python 侧的 `default=dict`。 ### ✅ 良好实践 - **防御性编程**:在 `_writeback_edit_plan_config` 中对 `plan_model.config` 进行了类型检查(`isinstance(plan_model.config, dict)`),防止因旧数据格式问题导致崩溃。 - **异常处理**:`_writeback_edit_plan_config` 捕获了所有异常并回滚事务,确保回写失败不影响主流程(任务创建)。 - **数据兼容**:在 Worker 渲染逻辑中,同时处理了新的 `title_config` 和旧的 `custom_title`,并做了字段名归一化(`font_size` -> `size`),保证了平滑过渡和向后兼容。 - **测试覆盖**:新增了 `test_writeback_edit_plan_config.py`,覆盖了空值、异常、回滚等多种边界情况。 --- <sub>🤖 由 AI 代码审查机器人自动生成 | 2026-08-23 05:41:09 | 模型: </sub> <!-- AI_CODE_REVIEW_AUTO_COMMENT -->
xiaoxia merged commit 94caa63436 into develop 2026-08-23 13:55:42 +08:00

🗑️ 预览环境已清理

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

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

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