From 9a3c307c758e20e18aa576358b646ae76f328703 Mon Sep 17 00:00:00 2001 From: malletfils Date: Thu, 16 Apr 2026 10:51:12 +0200 Subject: [PATCH] fix(history): populate status/error/engine fields from DB row (#394) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(history): populate status/error/engine/model_size/is_favorited from DB GET /history/{generation_id} was constructing HistoryResponse without passing status, error, engine, model_size, or is_favorited from the DB row. Since HistoryResponse.status defaults to "completed" in the Pydantic model (models.py:141), this endpoint returned status="completed" for every generation regardless of the actual DB state — including jobs still in "loading_model" or "generating", and even "failed" jobs. This breaks any client polling /history/{id} for job completion: the API lies about the status, so the only trustworthy success signal becomes `audio_path` being non-empty. All other fields left at their model defaults were similarly masked. Fix: pass all fields through from the DB row, matching the pattern used elsewhere in the codebase. The DB model (Generation in database/models.py) already has all these columns. * fix(history): apply NULL fallbacks to match list endpoint Align the defensive mappings with services/history.py:206-223 so both the single-item and list history endpoints handle legacy rows with NULL status/engine/is_favorited identically. Without this, HistoryResponse's non-Optional str/bool fields would raise a pydantic ValidationError (500) on any row where these columns are NULL — possible from direct SQL updates or past migrations. Addresses review feedback on PR #394. --------- Co-authored-by: malletfils <23569612+malletfils@users.noreply.github.com> --- backend/routes/history.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/backend/routes/history.py b/backend/routes/history.py index f8233e3c..df97b6f4 100644 --- a/backend/routes/history.py +++ b/backend/routes/history.py @@ -89,6 +89,11 @@ async def get_generation( duration=gen.duration, seed=gen.seed, instruct=gen.instruct, + engine=gen.engine or "qwen", + model_size=gen.model_size, + status=gen.status or "completed", + error=gen.error, + is_favorited=bool(gen.is_favorited), created_at=gen.created_at, )