-
Notifications
You must be signed in to change notification settings - Fork 23.2k
fix(api): stop swallowing document indexing errors in create handler #38192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
wylswz
merged 19 commits into
langgenius:main
from
Harsh23Kashyap:fix/create-document-index-error-handling
Jul 2, 2026
+99
−9
Merged
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 55d5668
test(api): add create_document_index event handler regression tests
Harsh23Kashyap 147c15f
merge upstream/main into fix/create-document-index-error-handling
Harsh23Kashyap 3af936d
fix(api): stop swallowing errors in create_document_index handler
Harsh23Kashyap 81192dd
test(api): add create_document_index event handler regression tests
Harsh23Kashyap 096865d
Merge branch 'fix/create-document-index-error-handling' of https://gi…
Harsh23Kashyap 3655dac
fix(api): log handler failures with logger.warning per review
Harsh23Kashyap f2463ca
merge upstream/main into fix/create-document-index-error-handling
Harsh23Kashyap 64d3e58
[autofix.ci] apply automated fixes
autofix-ci[bot] d61de4d
fix(web): tailwind class order in account-section
Harsh23Kashyap dc6fac0
Merge branch 'main' into fix/create-document-index-error-handling
Harsh23Kashyap 9cc668e
[autofix.ci] apply automated fixes
autofix-ci[bot] ed34aca
Merge branch 'main' into fix/create-document-index-error-handling
Harsh23Kashyap 3a7639b
merge upstream/main into fix/create-document-index-error-handling
bc33b49
Merge branch 'main' into fix/create-document-index-error-handling
Harsh23Kashyap 503a620
fix: use logger.exception to include exception details in error log
wylswz 78e35a0
Merge remote-tracking branch 'upstream/main' into fix/create-document…
Harsh23Kashyap 1b94011
Merge remote-tracking branch 'upstream/main' into fix/create-document…
Harsh23Kashyap 50edfb5
Merge remote-tracking branch 'upstream/main' into fix/create-document…
Harsh23Kashyap File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
api/tests/unit_tests/events/event_handlers/test_create_document_index.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.