Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
89a8029
fix(api): stop swallowing errors in create_document_index handler
Harsh23Kashyap Jun 30, 2026
55d5668
test(api): add create_document_index event handler regression tests
Harsh23Kashyap Jun 30, 2026
147c15f
merge upstream/main into fix/create-document-index-error-handling
Harsh23Kashyap Jun 30, 2026
3af936d
fix(api): stop swallowing errors in create_document_index handler
Harsh23Kashyap Jun 30, 2026
81192dd
test(api): add create_document_index event handler regression tests
Harsh23Kashyap Jun 30, 2026
096865d
Merge branch 'fix/create-document-index-error-handling' of https://gi…
Harsh23Kashyap Jul 1, 2026
3655dac
fix(api): log handler failures with logger.warning per review
Harsh23Kashyap Jul 1, 2026
f2463ca
merge upstream/main into fix/create-document-index-error-handling
Harsh23Kashyap Jul 1, 2026
64d3e58
[autofix.ci] apply automated fixes
autofix-ci[bot] Jul 1, 2026
d61de4d
fix(web): tailwind class order in account-section
Harsh23Kashyap Jul 1, 2026
dc6fac0
Merge branch 'main' into fix/create-document-index-error-handling
Harsh23Kashyap Jul 1, 2026
9cc668e
[autofix.ci] apply automated fixes
autofix-ci[bot] Jul 1, 2026
ed34aca
Merge branch 'main' into fix/create-document-index-error-handling
Harsh23Kashyap Jul 1, 2026
3a7639b
merge upstream/main into fix/create-document-index-error-handling
Jul 1, 2026
bc33b49
Merge branch 'main' into fix/create-document-index-error-handling
Harsh23Kashyap Jul 2, 2026
503a620
fix: use logger.exception to include exception details in error log
wylswz Jul 2, 2026
78e35a0
Merge remote-tracking branch 'upstream/main' into fix/create-document…
Harsh23Kashyap Jul 2, 2026
1b94011
Merge remote-tracking branch 'upstream/main' into fix/create-document…
Harsh23Kashyap Jul 2, 2026
50edfb5
Merge remote-tracking branch 'upstream/main' into fix/create-document…
Harsh23Kashyap Jul 2, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions api/events/event_handlers/create_document_index.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import contextlib
import logging
import time

Expand Down Expand Up @@ -42,11 +41,12 @@ def handle(sender, **kwargs):
session.add(document)
session.commit()

with contextlib.suppress(Exception):
try:
indexing_runner = IndexingRunner()
indexing_runner.run(documents)
end_at = time.perf_counter()
logger.info(click.style(f"Processed dataset: {dataset_id} latency: {end_at - start_at}", fg="green"))
except DocumentIsPausedError as ex:
logger.info(click.style(str(ex), fg="yellow"))
try:
indexing_runner = IndexingRunner()
indexing_runner.run(documents)
end_at = time.perf_counter()
logger.info(click.style(f"Processed dataset: {dataset_id} latency: {end_at - start_at}", fg="green"))
except DocumentIsPausedError as ex:
logger.info(click.style(str(ex), fg="yellow"))
Comment thread
Harsh23Kashyap marked this conversation as resolved.
except Exception:
logger.exception("Document index event handler failed, dataset_id: %s", dataset_id)
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import logging
from types import SimpleNamespace
from unittest.mock import MagicMock, patch

import pytest

from core.indexing_runner import DocumentIsPausedError
from events.event_handlers import create_document_index as handler_module


@pytest.fixture
def mock_document() -> SimpleNamespace:
return SimpleNamespace(
id="doc-1",
dataset_id="dataset-1",
indexing_status=None,
processing_started_at=None,
)


@pytest.fixture
def mock_session(mock_document: SimpleNamespace) -> MagicMock:
session = MagicMock()
session.scalar.return_value = mock_document
return session


@pytest.fixture
def mock_session_factory(mock_session: MagicMock) -> MagicMock:
factory = MagicMock()
factory.create_session.return_value.__enter__.return_value = mock_session
factory.create_session.return_value.__exit__.return_value = None
return factory


@pytest.fixture
def mock_indexing_runner() -> MagicMock:
return MagicMock()


def test_handle_logs_document_pause(
mock_session_factory: MagicMock,
mock_indexing_runner: MagicMock,
caplog: pytest.LogCaptureFixture,
) -> None:
mock_indexing_runner.run.side_effect = DocumentIsPausedError("Document is paused")

with (
patch.object(handler_module, "session_factory", mock_session_factory),
patch.object(handler_module, "IndexingRunner", return_value=mock_indexing_runner),
):
with caplog.at_level(logging.INFO, logger=handler_module.logger.name):
handler_module.handle("dataset-1", document_ids=["doc-1"])

assert "Document is paused" in caplog.text


def test_handle_logs_unexpected_indexing_errors(
mock_session_factory: MagicMock,
mock_indexing_runner: MagicMock,
caplog: pytest.LogCaptureFixture,
) -> None:
mock_indexing_runner.run.side_effect = RuntimeError("Indexing failed")

with (
patch.object(handler_module, "session_factory", mock_session_factory),
patch.object(handler_module, "IndexingRunner", return_value=mock_indexing_runner),
):
with caplog.at_level(logging.ERROR, logger=handler_module.logger.name):
handler_module.handle("dataset-1", document_ids=["doc-1"])

assert any(record.levelno >= logging.ERROR for record in caplog.records)
assert "Document index event handler failed" in caplog.text
assert "Indexing failed" in caplog.text


def test_handle_runs_indexing_on_success(
mock_session_factory: MagicMock,
mock_indexing_runner: MagicMock,
caplog: pytest.LogCaptureFixture,
) -> None:
with (
patch.object(handler_module, "session_factory", mock_session_factory),
patch.object(handler_module, "IndexingRunner", return_value=mock_indexing_runner),
):
with caplog.at_level(logging.INFO, logger=handler_module.logger.name):
handler_module.handle("dataset-1", document_ids=["doc-1"])

mock_indexing_runner.run.assert_called_once()
assert "Processed dataset: dataset-1" in caplog.text
Loading