fix(connectors): refresh document from DB before updating type

- Query document from database to ensure it's attached to session
- Prevents detached instance errors after process_file_in_background commits
- Properly updates document_type and metadata with session management
This commit is contained in:
CREDO23 2025-12-28 17:21:44 +02:00
parent b2b891e4d7
commit 8da58be9e0

View file

@ -408,6 +408,20 @@ async def _process_single_file(
return 0, 1
if document and file_metadata:
# Refresh document from database to ensure it's attached to session
from app.db import Document
from sqlalchemy import select
# Get fresh document from database
result = await session.execute(
select(Document).where(Document.id == document.id)
)
document = result.scalar_one_or_none()
if not document:
logger.error(f"Could not find document {document.id} in database")
return 0, 1
# Update document type to GOOGLE_DRIVE_CONNECTOR and add metadata
original_type = document.document_type
document.document_type = DocumentType.GOOGLE_DRIVE_CONNECTOR