Fix 500 error on knowledge base Process Documents
knowledge_base_service and analysis_service were local variables inside the lifespan() function — not module-level exports. Importing them via 'from app.main import ...' always failed with ImportError → 500. Use request.app.state (same pattern as analysis_routes.py) instead. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
aeab7d3b18
commit
71639030ba
1 changed files with 5 additions and 3 deletions
|
|
@ -2,7 +2,7 @@
|
|||
import difflib
|
||||
import uuid
|
||||
|
||||
from fastapi import APIRouter, BackgroundTasks, Depends, HTTPException, UploadFile, File
|
||||
from fastapi import APIRouter, BackgroundTasks, Depends, HTTPException, Request, UploadFile, File
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.api.knowledge_base_schemas import (
|
||||
|
|
@ -220,12 +220,13 @@ async def delete_source_document(
|
|||
@kb_router.post("/{kb_id}/process", response_model=ProcessingJobResponse, status_code=201)
|
||||
async def trigger_processing(
|
||||
kb_id: uuid.UUID,
|
||||
request: Request,
|
||||
background_tasks: BackgroundTasks,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
user: dict = Depends(get_current_user),
|
||||
):
|
||||
"""Trigger the document processing pipeline for a knowledge base."""
|
||||
from app.main import knowledge_base_service as kb_service
|
||||
kb_service = getattr(request.app.state, "knowledge_base_service", None)
|
||||
|
||||
if kb_service is None:
|
||||
raise HTTPException(
|
||||
|
|
@ -448,6 +449,7 @@ async def get_spec_diff(
|
|||
async def activate_spec_version(
|
||||
kb_id: uuid.UUID,
|
||||
version_id: uuid.UUID,
|
||||
request: Request,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
user: dict = Depends(get_current_user),
|
||||
):
|
||||
|
|
@ -460,7 +462,7 @@ async def activate_spec_version(
|
|||
# Invalidate reference docs cache
|
||||
kb = await repo.get_knowledge_base(kb_id)
|
||||
if kb:
|
||||
from app.main import analysis_service
|
||||
analysis_service = getattr(request.app.state, "analysis_service", None)
|
||||
if analysis_service:
|
||||
analysis_service.reference_docs.invalidate_cache(kb.agent_key)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue