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 <noreply@anthropic.com>
This commit is contained in:
michael 2026-02-12 16:09:50 -06:00
parent 3aa99144d4
commit 7835f557aa

View file

@ -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(