From 080ef6ab004f8e3f0e9043a8583ad7091fc508e4 Mon Sep 17 00:00:00 2001 From: wuyongtao Date: Wed, 19 Aug 2026 16:43:36 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=AF=84=E6=B5=8B=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E8=BD=AF=E5=88=A0=E9=99=A4=E5=81=A5=E5=A3=AE=E6=80=A7=E5=A2=9E?= =?UTF-8?q?=E5=BC=BA=EF=BC=8C=E5=88=A0=E9=99=A4=E4=B8=8D=E5=AD=98=E5=9C=A8?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E8=BF=94=E5=9B=9E=20404?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - delete_eval_task 用 RETURNING 校验记录存在性与重复删除,否则抛 KeyError - eval_tasks/eval_task 列表与详情过滤已软删除记录(deleted_at IS NULL) - model_eval_delete 捕获 KeyError 返回 404,避免接口崩溃 Co-Authored-By: Claude --- backend/app/api/v1/endpoints/platform.py | 5 ++++- backend/app/db/platform_store.py | 18 +++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/backend/app/api/v1/endpoints/platform.py b/backend/app/api/v1/endpoints/platform.py index f3387b3..34a77ba 100644 --- a/backend/app/api/v1/endpoints/platform.py +++ b/backend/app/api/v1/endpoints/platform.py @@ -2305,7 +2305,10 @@ async def model_eval_delete(task_id: str, current_user: dict = Depends(get_curre pending = _require_approval_or_admin("eval", task_id, current_user, f"删除评测任务 {task_id}") if pending: return pending - get_platform_store().delete_eval_task(task_id) + try: + get_platform_store().delete_eval_task(task_id) + except KeyError: + raise fail(404, "eval task not found") return ok({"deleted": task_id}) diff --git a/backend/app/db/platform_store.py b/backend/app/db/platform_store.py index 2474354..ce35551 100644 --- a/backend/app/db/platform_store.py +++ b/backend/app/db/platform_store.py @@ -2515,12 +2515,18 @@ class PlatformStore: def eval_tasks(self) -> list[dict[str, Any]]: with self.connect() as conn: - rows = conn.execute("SELECT * FROM eval_tasks ORDER BY create_time DESC").fetchall() + # 评测任务采用软删除,普通列表不得再次返回已删除记录。 + rows = conn.execute( + "SELECT * FROM eval_tasks WHERE deleted_at IS NULL ORDER BY create_time DESC" + ).fetchall() return [self._enrich_eval_payload(conn, self._json_payload_row(row)) for row in rows] def eval_task(self, task_id: str) -> dict[str, Any]: with self.connect() as conn: - row = conn.execute("SELECT * FROM eval_tasks WHERE id=?", (task_id,)).fetchone() + row = conn.execute( + "SELECT * FROM eval_tasks WHERE id=? AND deleted_at IS NULL", + (task_id,), + ).fetchone() if not row: raise KeyError(task_id) payload = self._enrich_eval_payload(conn, self._json_payload_row(row)) @@ -2591,7 +2597,13 @@ class PlatformStore: def delete_eval_task(self, task_id: str) -> None: with self.connect() as conn: - conn.execute("UPDATE eval_tasks SET deleted_at=?, deleted_by=? WHERE id=?", (utcnow(), "system", task_id)) + result = conn.execute( + "UPDATE eval_tasks SET deleted_at=?, deleted_by=? " + "WHERE id=? AND deleted_at IS NULL RETURNING id", + (utcnow(), "system", task_id), + ) + if not result.fetchone(): + raise KeyError(task_id) def running_eval_tasks(self) -> list[dict[str, Any]]: """Return eval tasks that have been submitted to a compute node and are still running."""