From 558d965a1c944df7d25b35cc03f82ce0ce2c07d4 Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Mon, 29 Jun 2026 11:39:11 -0400 Subject: [PATCH] fix(gpu): count backfill enqueues via RETURNING, not rowcount MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit result.rowcount is unreliable for INSERT…SELECT (returned -1), failing the idempotency assert. Use .returning(GpuJob.id) and count the rows. (run 1652) Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01Ttrj5P7upUTueSfoJcxEqa --- backend/app/tasks/ml.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/backend/app/tasks/ml.py b/backend/app/tasks/ml.py index 708aa22..ecdfcbd 100644 --- a/backend/app/tasks/ml.py +++ b/backend/app/tasks/ml.py @@ -760,10 +760,11 @@ def enqueue_gpu_backfill(task_name: str) -> int: sel = sa_select( ImageRecord.id, literal(task_name), literal("pending") ).where(~already) - result = session.execute( - insert(GpuJob).from_select( - ["image_record_id", "task", "status"], sel - ) - ) + # RETURNING + count: result.rowcount is unreliable for INSERT…SELECT. + rows = session.execute( + insert(GpuJob) + .from_select(["image_record_id", "task", "status"], sel) + .returning(GpuJob.id) + ).fetchall() session.commit() - return result.rowcount or 0 + return len(rows)