fix(#1769): 模板列表过滤无片段配置的无效模板,避免前端选中后400 #1772

Merged
auto-approve-bot merged 3 commits from fix/filter-invalid-templates-1769 into develop 2026-09-08 00:10:15 +08:00
Owner

根因

智能剪辑页 Step1 加载模板列表后,前端自动选中第一个模板(useTemplateSelection.tsuserTemplates[0].id)。但数据库中存在 template_clip_configstemplate_segments 两张表都没有记录 的无效模板(如历史测试残留/创建流程中断产生的垃圾数据)。前端选中这类模板后,Step2 调用 POST /api/v1/templates/{id}/clips/from-assets 返回 400「模板没有片段配置,无法创建片段」,导致素材无法写入、播放器无内容。

27dccf65 仅在 clips 路由加了错误日志,未做真正过滤,本 PR 为彻底修复。

修改点

后端(核心修复)

  • GET /api/v1/templates 新增查询参数 valid_only(默认 false):
    • valid_only=true:通过 EXISTS 子查询排除两张片段表都无记录的模板,列表查询与 total 计数共用同一过滤逻辑(SQLAlchemyTemplateRepository._filter_with_segment_configs
    • 默认不过滤:模板编辑器 / 我的模板页面不传该参数,仍可看到全部模板(含尚未配置片段的草稿),编辑器功能不受影响
  • 全链路透传:ListTemplatesFilterListTemplatesUseCase / CountTemplatesUseCaseTemplateRepositoryPortSQLAlchemyTemplateRepository.list_by_user/count_by_user

前端(双保险)

  • getEditingTemplates 支持 validOnly 参数(序列化为 valid_only
  • 剪辑页 useTemplateSelection 请求时传 { validOnly: true };自动选中逻辑改为选中第一个 segments.length > 0 的模板(即使后端过滤有遗漏,前端也不会选中空模板)
  • 编辑器(editing-planner/useTemplateList)和我的模板(useMyTemplates)不传该参数,行为不变

测试

  • tests/unit/test_unify_template_segments.py 新增 2 个用例:验证 valid_only=True 过滤无片段模板(含旧表回退数据判定)、与 mode 等过滤条件及分页组合使用
  • 后端 115 个相关单测全部通过;前端 tsc / eslint / prettier 及相关页面测试全部通过

验收

  • 剪辑页模板列表不再返回无片段配置的模板,自动选中不会命中无效模板
  • 模板编辑器/我的模板仍展示全部模板,草稿可正常编辑
  • 改动为替换式,无废弃代码残留
## 根因 智能剪辑页 Step1 加载模板列表后,前端自动选中第一个模板(`useTemplateSelection.ts` → `userTemplates[0].id`)。但数据库中存在 **在 `template_clip_configs` 和 `template_segments` 两张表都没有记录** 的无效模板(如历史测试残留/创建流程中断产生的垃圾数据)。前端选中这类模板后,Step2 调用 `POST /api/v1/templates/{id}/clips/from-assets` 返回 400「模板没有片段配置,无法创建片段」,导致素材无法写入、播放器无内容。 `27dccf65` 仅在 clips 路由加了错误日志,未做真正过滤,本 PR 为彻底修复。 ## 修改点 ### 后端(核心修复) - `GET /api/v1/templates` 新增查询参数 `valid_only`(默认 `false`): - `valid_only=true`:通过 EXISTS 子查询排除两张片段表都无记录的模板,列表查询与 total 计数共用同一过滤逻辑(`SQLAlchemyTemplateRepository._filter_with_segment_configs`) - 默认不过滤:**模板编辑器 / 我的模板页面不传该参数,仍可看到全部模板(含尚未配置片段的草稿),编辑器功能不受影响** - 全链路透传:`ListTemplatesFilter` → `ListTemplatesUseCase` / `CountTemplatesUseCase` → `TemplateRepositoryPort` → `SQLAlchemyTemplateRepository.list_by_user/count_by_user` ### 前端(双保险) - `getEditingTemplates` 支持 `validOnly` 参数(序列化为 `valid_only`) - 剪辑页 `useTemplateSelection` 请求时传 `{ validOnly: true }`;自动选中逻辑改为选中第一个 `segments.length > 0` 的模板(即使后端过滤有遗漏,前端也不会选中空模板) - 编辑器(`editing-planner/useTemplateList`)和我的模板(`useMyTemplates`)不传该参数,行为不变 ### 测试 - `tests/unit/test_unify_template_segments.py` 新增 2 个用例:验证 `valid_only=True` 过滤无片段模板(含旧表回退数据判定)、与 mode 等过滤条件及分页组合使用 - 后端 115 个相关单测全部通过;前端 tsc / eslint / prettier 及相关页面测试全部通过 ## 验收 - [x] 剪辑页模板列表不再返回无片段配置的模板,自动选中不会命中无效模板 - [x] 模板编辑器/我的模板仍展示全部模板,草稿可正常编辑 - [x] 改动为替换式,无废弃代码残留

🚀 预览环境已部署

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

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

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

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

🚀 **预览环境已部署** | 项目 | 详情 | |------|------| | PR号 | #1772 | | 预览链接 | [https://pr-1772.preview.xiaoxiajianji.com](https://pr-1772.preview.xiaoxiajianji.com) | | API环境 | staging | > 💡 预览环境使用 staging API 数据,请勿在预览环境中操作重要数据。 > > 🔄 每次提交新代码后预览环境会自动更新。 > > 🗑️ PR 关闭或合并后,预览环境会自动清理。
xiaoxia added 1 commit 2026-09-07 23:48:58 +08:00
fix(#1769): 模板列表支持 valid_only 过滤无片段配置的无效模板
CI/CD Pipeline / Check push changed paths (pull_request) Has been skipped
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 2s
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (pull_request) Successful in 2s
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 / 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 / Retag skipped Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped 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 / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 28s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 27s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 1m22s
CI/CD Pipeline / Validate - Style (pull_request) Successful in 1m40s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 1m54s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 2m50s
CI/CD Pipeline / Validate - Python (mypy + alembic) (pull_request) Successful in 2m56s
CI/CD Pipeline / Unit Tests (pull_request) Failing after 3m19s
AI Code Review / AI Code Review (pull_request) Successful in 6m35s
CI/CD Pipeline / Validate - Security (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 Merge on CI Green + Approved (pull_request) Has been cancelled
71a47f7fb7
根因:数据库存在 template_clip_configs 和 template_segments 两表都没有
记录的无效模板,剪辑页 Step1 自动选中这类模板后,Step2 调用
POST /templates/{id}/clips/from-assets 返回 400「模板没有片段配置」,
导致素材无法写入、播放器无内容。

修复:
- 后端 GET /templates 新增 valid_only 查询参数(默认 false,不影响
  模板编辑器/我的模板等管理场景,草稿模板仍可见)
- 仓储层 list_by_user/count_by_user 通过 EXISTS 子查询过滤掉两张
  片段表都无记录的模板,列表与计数共用同一过滤逻辑
- Port/Filter/UseCase 全链路透传 valid_only
- 前端剪辑页 useTemplateSelection 请求时传 validOnly=true,并在自动
  选中时跳过 segments 为空的模板(双保险)
- 补充仓储层单元测试覆盖过滤逻辑
xiaoxia force-pushed fix/filter-invalid-templates-1769 from 61e84eea93 to 71a47f7fb7 2026-09-07 23:48:58 +08:00 Compare
xiaoxia added 1 commit 2026-09-07 23:59:30 +08:00
test(#1769): 修正 valid_only 参数相关的 mock 调用断言
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (pull_request) Successful in 1s
CI/CD Pipeline / Check push changed paths (pull_request) Has been skipped
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 1s
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 API Image (pull_request) Successful in 26s
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 / Retag skipped Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 45s
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 / Validate - Style (pull_request) Has been cancelled
CI/CD Pipeline / Validate - Security (pull_request) Has been cancelled
CI/CD Pipeline / Validate - Python (mypy + alembic) (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
AI Code Review / AI Code Review (pull_request) Has been cancelled
PR Automation / Auto Approve on CI Green (pull_request) Has been cancelled
PR Automation / Auto Merge on CI Green + Approved (pull_request) Has been cancelled
Preview Deploy / Deploy Preview Environment (pull_request) Has been cancelled
77de2f029b
xiaoxia added 1 commit 2026-09-08 00:00:35 +08:00
test(#1769): 无 filter 场景不传 valid_only,修正断言
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 2s
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (pull_request) Successful in 3s
CI/CD Pipeline / Check push changed paths (pull_request) Has been skipped
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 / 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 / PR Build API Image (pull_request) Successful in 22s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 26s
CI/CD Pipeline / Retag skipped Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped 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 / Integration Tests (pull_request) Successful in 1m5s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 1m30s
CI/CD Pipeline / Validate - Python (mypy + alembic) (pull_request) Successful in 2m5s
CI/CD Pipeline / Validate - Style (pull_request) Successful in 2m30s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 2m45s
AI Code Review / AI Code Review (pull_request) Successful in 6m36s
CI/CD Pipeline / Validate - Security (pull_request) Successful in 8m22s
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 / CI Gate (pull_request) Successful in 7s
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / Canary Release to Production (pull_request) Has been skipped
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 6m40s
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 31s
ACR Cleanup / ACR Image Cleanup (pull_request_target) Successful in 47s
Preview Deploy / Deploy Preview Environment (pull_request) Failing after 13m25s
7f9d2e5488
auto-approve-bot merged commit ef686dde8f into develop 2026-09-08 00:10:15 +08:00
auto-approve-bot deleted branch fix/filter-invalid-templates-1769 2026-09-08 00:10:17 +08:00

🗑️ 预览环境已清理

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

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

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