fix: cover.py step3 改用 user+template 查找预览任务;删除 generation.py 冗余 rendered_url
CI/CD Pipeline / Frontend Unit Tests (push) Successful in 1m33s
CI/CD Pipeline / Validate - Migration (alembic) (push) Successful in 1m36s
CI/CD Pipeline / Validate - Type Check (mypy) (push) Successful in 2m24s
CI/CD Pipeline / Build Staging Web Image (push) Successful in 2m31s
CI/CD Pipeline / Build Staging Worker Image (push) Successful in 5m7s
CI/CD Pipeline / Validate - Code Quality (push) Successful in 6m38s
CI/CD Pipeline / Integration Tests (push) Successful in 1m58s
CI/CD Pipeline / Unit Tests (push) Successful in 9m9s
CI/CD Pipeline / Build Staging API Image (push) Successful in 12m11s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Successful in 48s
CI/CD Pipeline / ACR Image Cleanup (push) Successful in 36s
CI/CD Pipeline / Staging E2E Tests (push) Successful in 44s
CI/CD Pipeline / Staging API Integration Tests (push) Successful in 2m51s
CI/CD Pipeline / Canary Release to Production (push) Failing after 855h3m55s
CI/CD Pipeline / Deploy Production (push) Failing after 855h10m36s
CI/CD Pipeline / CI Gate (push) Failing after 855h10m36s
CI/CD Pipeline / Build Production Web Image (push) Failing after 855h10m37s
CI/CD Pipeline / Build Production API Image (push) Failing after 855h10m37s
CI/CD Pipeline / PR Build Web Image (push) Failing after 855h19m46s
CI/CD Pipeline / PR Build API Image (push) Failing after 855h19m47s
CI/CD Pipeline / Check if frontend-only change (push) Failing after 855h19m48s
CI/CD Pipeline / Production Browser E2E (push) Failing after 855h44m5s
CI/CD Pipeline / Build Production Worker Image (push) Failing after 855h44m6s
CI/CD Pipeline / PR Build Worker Image (push) Failing after 855h53m15s
CI/CD Pipeline / Frontend Lint (push) Failing after 855h53m16s

P0 修复:预览任务创建时 plan_id 尚未存在,source_edit_plan_id 始终为空,
导致封面生成第三步查找永远匹配不到。改为按 user_id + template_id + is_preview +
status=completed 查找最近预览任务。

技术债:generation.py 复用预览产物分支删除冗余 rendered_url 写入,
统一只写 rendered_storage_key。

新增 repository 方法:list_latest_completed_preview(user_id, template_id)
This commit is contained in:
CI Bot
2026-08-12 00:07:06 +08:00
parent cb1ba46d30
commit 7d6c0cc67e
3 changed files with 27 additions and 12 deletions
@@ -79,32 +79,32 @@ def editor_generate_cover(
exc_info=True,
)
# 第三步:如果还没有,通过 source_edit_plan_id 查找最近完成的预览任务
# 第三步:按 user + template 查找最近的已完成预览任务(兜底)
if not rendered_storage_key:
try:
gen_task_repo = SQLAlchemyGenerationTaskRepository(db)
preview_tasks = gen_task_repo.list_by_source_edit_plan(plan_id)
# 过滤 is_preview=True + is_completed,取最新的
completed_preview = None
for t in preview_tasks:
if getattr(t, "is_preview", False) and t.is_completed:
completed_preview = t
break # list_by_source_edit_plan 已按创建时间倒序
if completed_preview:
preview_tasks = gen_task_repo.list_latest_completed_preview(
user_id=str(current_user.user.id),
template_id=template_id,
)
if preview_tasks:
completed_preview = preview_tasks[0]
video_repo = get_generated_video_repository(db)
use_case = ListGeneratedVideosByTaskUseCase(video_repo)
videos = use_case.execute(completed_preview.id)
if videos:
rendered_storage_key = getattr(videos[0], "file_url", "") or ""
logger.info(
"封面生成: 通过 source_edit_plan_id 找到视频: plan_id=%s task_id=%s",
"封面视频: 通过 user+template 找到预览任务: plan_id=%s template_id=%s task_id=%s",
plan_id,
template_id,
completed_preview.id,
)
except Exception:
logger.warning(
"封面生成: 通过 source_edit_plan_id 查找视频失败: plan_id=%s",
"封面警告: user+template 查找预览任务失败: plan_id=%s template_id=%s",
plan_id,
template_id,
exc_info=True,
)
@@ -96,7 +96,6 @@ def generate_editor_draft(
plan_id,
{
"generation_task_id": reusable_task.id,
"rendered_url": rendered_url,
"rendered_storage_key": rendered_url, # 统一用 rendered_storage_key
},
)
@@ -148,6 +148,22 @@ class SQLAlchemyGenerationTaskRepository:
)
return [_to_domain(m) for m in models]
def list_latest_completed_preview(self, user_id: str, template_id: str, limit: int = 1) -> list[GenerationTask]:
"""按用户+模板查找最近已完成的预览任务。"""
models = (
self.session.query(GenerationTaskModel)
.filter(
GenerationTaskModel.created_by_user_id == user_id,
GenerationTaskModel.template_id == template_id,
GenerationTaskModel.is_preview,
GenerationTaskModel.status == "completed",
)
.order_by(GenerationTaskModel.created_at.desc())
.limit(limit)
.all()
)
return [_to_domain(m) for m in models]
def list_by_source_edit_plan(self, plan_id: str) -> list[GenerationTask]:
models = (
self.session.query(GenerationTaskModel)