From c26181d0867267e1cfef95baf42150056a429ffd Mon Sep 17 00:00:00 2001 From: CREDO23 Date: Wed, 10 Jun 2026 00:10:52 +0200 Subject: [PATCH] fix(airtable): commit failed status immediately --- .../app/tasks/connector_indexers/airtable_indexer.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/surfsense_backend/app/tasks/connector_indexers/airtable_indexer.py b/surfsense_backend/app/tasks/connector_indexers/airtable_indexer.py index ac38b7bf7..e2a1b109a 100644 --- a/surfsense_backend/app/tasks/connector_indexers/airtable_indexer.py +++ b/surfsense_backend/app/tasks/connector_indexers/airtable_indexer.py @@ -6,6 +6,7 @@ Implements real-time document status updates using a two-phase approach: - Phase 2: Process each document one by one (pending → processing → ready/failed) """ +import contextlib import time from collections.abc import Awaitable, Callable @@ -432,10 +433,15 @@ async def index_airtable_records( try: document.status = DocumentStatus.failed(str(e)) document.updated_at = get_current_timestamp() + # Commit now so the failed status survives a later rollback or + # crash; otherwise the doc stays stuck in pending/processing. + await session.commit() except Exception as status_error: logger.error( f"Failed to update document status to failed: {status_error}" ) + with contextlib.suppress(Exception): + await session.rollback() documents_failed += 1 continue