From 7835f557aaf71319b961611020f8cc9b5050d079 Mon Sep 17 00:00:00 2001 From: michael Date: Thu, 12 Feb 2026 16:09:50 -0600 Subject: [PATCH] Fix processing job not visible to background task (FK violation) The background task runs in its own DB session but the job row hadn't been committed yet by the request session. The background task couldn't find the job, causing FK violations when trying to create spec_versions. Fix: explicitly commit the request session after creating the job and before adding the background task, ensuring the job row is visible. Co-Authored-By: Claude Opus 4.6 --- backend/app/api/knowledge_base_routes.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backend/app/api/knowledge_base_routes.py b/backend/app/api/knowledge_base_routes.py index 969fd8c..e832e95 100644 --- a/backend/app/api/knowledge_base_routes.py +++ b/backend/app/api/knowledge_base_routes.py @@ -253,13 +253,14 @@ async def trigger_processing( user_id, user_name = await _get_user_info(db, user) - # Create the job + # Create the job and commit immediately so the background task can see it job = await repo.create_processing_job( knowledge_base_id=kb_id, total_documents=len(docs), triggered_by_id=user_id, triggered_by_name=user_name, ) + await db.commit() # Start background processing background_tasks.add_task(