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)