From f3888864cf5654f331378390d2a3bac7559b5247 Mon Sep 17 00:00:00 2001 From: ABD Date: Wed, 15 Apr 2026 13:09:18 +0530 Subject: [PATCH 1/3] fix: remove extra arg from dry-run logger.info call MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #2254 — logger.info() was called with an extra True positional argument and no matching %s placeholder, causing TypeError with some logging backends (e.g. Ollama). --- .semversioner/next-release/patch-20260415073659562608.json | 4 ++++ packages/graphrag/graphrag/cli/index.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 .semversioner/next-release/patch-20260415073659562608.json diff --git a/.semversioner/next-release/patch-20260415073659562608.json b/.semversioner/next-release/patch-20260415073659562608.json new file mode 100644 index 0000000000..438ee09644 --- /dev/null +++ b/.semversioner/next-release/patch-20260415073659562608.json @@ -0,0 +1,4 @@ +{ + "type": "patch", + "description": "Fix TypeError in dry-run logging caused by extra positional argument with no format placeholder." +} diff --git a/packages/graphrag/graphrag/cli/index.py b/packages/graphrag/graphrag/cli/index.py index 94a40cde48..68022eb9e5 100644 --- a/packages/graphrag/graphrag/cli/index.py +++ b/packages/graphrag/graphrag/cli/index.py @@ -116,7 +116,7 @@ def _run_index( ) if dry_run: - logger.info("Dry run complete, exiting...", True) + logger.info("Dry run complete, exiting...") sys.exit(0) _register_signal_handlers() From 7c2874dbe0601d2ceb4c8255f64b1d292eaf83a9 Mon Sep 17 00:00:00 2001 From: ABD Date: Wed, 15 Apr 2026 19:00:31 +0530 Subject: [PATCH 2/3] test: add unit tests for dry-run logging fix (issue #2254) --- tests/unit/indexing/test_index_cli.py | 92 +++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 tests/unit/indexing/test_index_cli.py diff --git a/tests/unit/indexing/test_index_cli.py b/tests/unit/indexing/test_index_cli.py new file mode 100644 index 0000000000..73a3e03111 --- /dev/null +++ b/tests/unit/indexing/test_index_cli.py @@ -0,0 +1,92 @@ +# Copyright (C) 2024 Microsoft Corporation. +# Licensed under the MIT License + +"""Unit tests for the index CLI dry-run path.""" + +import logging +from unittest.mock import MagicMock, patch + +import pytest + +from graphrag.cli.index import _run_index +from graphrag.config.enums import IndexingMethod + + +class TestDryRunLogging: + """Tests that the dry-run path logs correctly without extra positional args.""" + + def _make_config(self): + """Return a minimal mock config object.""" + config = MagicMock() + config.cache.type = "memory" + config.model_dump.return_value = {} + return config + + @patch("graphrag.cli.index.sys.exit") + @patch("graphrag.cli.index.validate_config_names") + @patch("graphrag.cli.index.init_loggers") + def test_dry_run_exits_zero(self, mock_init_loggers, mock_validate, mock_exit): + """Dry run must call sys.exit(0) and not raise TypeError.""" + config = self._make_config() + + _run_index( + config=config, + method=IndexingMethod.Standard, + is_update_run=False, + verbose=False, + cache=True, + dry_run=True, + skip_validation=True, + ) + + mock_exit.assert_called_once_with(0) + + @patch("graphrag.cli.index.sys.exit") + @patch("graphrag.cli.index.validate_config_names") + @patch("graphrag.cli.index.init_loggers") + def test_dry_run_logs_no_extra_args( + self, mock_init_loggers, mock_validate, mock_exit, caplog + ): + """Dry run logger.info call must not pass extra positional args. + + Regression test for Issue #2254 — logger.info("Dry run complete, + exiting...", True) raised TypeError with certain logging backends. + The fixed call passes no extra args. + """ + config = self._make_config() + + with caplog.at_level(logging.INFO, logger="graphrag.cli.index"): + _run_index( + config=config, + method=IndexingMethod.Standard, + is_update_run=False, + verbose=False, + cache=True, + dry_run=True, + skip_validation=True, + ) + + # The "Dry run complete" message must appear in the log output. + assert any("Dry run complete" in r.getMessage() for r in caplog.records) + + @patch("graphrag.cli.index.sys.exit") + @patch("graphrag.cli.index.validate_config_names") + @patch("graphrag.cli.index.init_loggers") + def test_dry_run_does_not_run_pipeline( + self, mock_init_loggers, mock_validate, mock_exit + ): + """When dry_run=True, the async pipeline must not be invoked.""" + config = self._make_config() + + with patch("graphrag.cli.index.asyncio.run") as mock_run: + _run_index( + config=config, + method=IndexingMethod.Standard, + is_update_run=False, + verbose=False, + cache=True, + dry_run=True, + skip_validation=True, + ) + + mock_run.assert_not_called() From 44b86ef4e045d590474a85cbd7700bc65e505542 Mon Sep 17 00:00:00 2001 From: ABD Date: Wed, 15 Apr 2026 19:06:00 +0530 Subject: [PATCH 3/3] fix: remove unused pytest import, fix import order in test --- tests/unit/indexing/test_index_cli.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/unit/indexing/test_index_cli.py b/tests/unit/indexing/test_index_cli.py index 73a3e03111..e4f343e505 100644 --- a/tests/unit/indexing/test_index_cli.py +++ b/tests/unit/indexing/test_index_cli.py @@ -6,8 +6,6 @@ import logging from unittest.mock import MagicMock, patch -import pytest - from graphrag.cli.index import _run_index from graphrag.config.enums import IndexingMethod