fix: update Google Drive indexer to use SQLAlchemy casting for metadata queries

- Modified the Google Drive indexer to use SQLAlchemy's cast function for querying document metadata, ensuring proper type handling for file IDs.
- Improved the consistency of metadata queries across the indexing functions, enhancing reliability in document retrieval and processing.
This commit is contained in:
Anish Sarkar 2026-01-24 04:33:10 +05:30
parent 5cf6fb15ed
commit 97d7207bd4

View file

@ -578,7 +578,7 @@ async def _check_rename_only_update(
- (True, message): Only filename changed, document was updated
- (False, None): Content changed or new file, needs full processing
"""
from sqlalchemy import select
from sqlalchemy import cast, select, String
from sqlalchemy.orm.attributes import flag_modified
from app.db import Document
@ -603,7 +603,7 @@ async def _check_rename_only_update(
select(Document).where(
Document.search_space_id == search_space_id,
Document.document_type == DocumentType.GOOGLE_DRIVE_FILE,
Document.document_metadata["google_drive_file_id"].astext == file_id,
cast(Document.document_metadata["google_drive_file_id"], String) == file_id,
)
)
existing_document = result.scalar_one_or_none()
@ -755,7 +755,7 @@ async def _remove_document(session: AsyncSession, file_id: str, search_space_id:
Handles both new (file_id-based) and legacy (filename-based) hash schemes.
"""
from sqlalchemy import select
from sqlalchemy import cast, select, String
from app.db import Document
@ -774,7 +774,7 @@ async def _remove_document(session: AsyncSession, file_id: str, search_space_id:
select(Document).where(
Document.search_space_id == search_space_id,
Document.document_type == DocumentType.GOOGLE_DRIVE_FILE,
Document.document_metadata["google_drive_file_id"].astext == file_id,
cast(Document.document_metadata["google_drive_file_id"], String) == file_id,
)
)
existing_document = result.scalar_one_or_none()