From f26889bbf6038401e2295389853ced9fe55d016e Mon Sep 17 00:00:00 2001 From: Saltaferis Dimitrios Date: Wed, 2 Dec 2026 10:12:29 +0000 Subject: [PATCH 1/4] feat(constants): add DEFAULT_MAX_CONCURRENT_EXECUTION for the batch concurrency default Co-Authored-By: Claude Opus 5.5 --- infrahub_sdk/constants.py | 4 +++- tests/unit/sdk/test_batch.py | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/infrahub_sdk/constants.py b/infrahub_sdk/constants.py index 03e6302ac..1cd5e5a47 100644 --- a/infrahub_sdk/constants.py +++ b/infrahub_sdk/constants.py @@ -1,7 +1,9 @@ -"""Enumerations shared across the Infrahub SDK.""" +"""Enumerations and constants shared across the Infrahub SDK.""" import enum +DEFAULT_MAX_CONCURRENT_EXECUTION = 5 + class InfrahubClientMode(str, enum.Enum): DEFAULT = "default" diff --git a/tests/unit/sdk/test_batch.py b/tests/unit/sdk/test_batch.py index 7bdf00ad9..da7578094 100644 --- a/tests/unit/sdk/test_batch.py +++ b/tests/unit/sdk/test_batch.py @@ -4,6 +4,7 @@ import pytest +from infrahub_sdk.constants import DEFAULT_MAX_CONCURRENT_EXECUTION from infrahub_sdk.exceptions import GraphQLError if TYPE_CHECKING: @@ -14,6 +15,11 @@ client_types = ["standard", "sync"] +def test_default_max_concurrent_execution_value() -> None: + assert DEFAULT_MAX_CONCURRENT_EXECUTION == 5 + assert isinstance(DEFAULT_MAX_CONCURRENT_EXECUTION, int) + + @pytest.mark.parametrize("client_type", client_types) async def test_batch_execution(clients: BothClients, client_type: str) -> None: r: list[int] = [] From 873db171489ee643350122a00a35a6aa05aaeaad Mon Sep 17 00:00:00 2001 From: Saltaferis Dimitrios Date: Wed, 2 Dec 2026 10:13:43 +0000 Subject: [PATCH 2/4] refactor(batch): use DEFAULT_MAX_CONCURRENT_EXECUTION as the batch and config default Co-Authored-By: Claude Opus 5.5 --- infrahub_sdk/batch.py | 8 ++++++-- infrahub_sdk/config.py | 6 ++++-- tests/unit/sdk/test_batch.py | 12 ++++++++++++ tests/unit/sdk/test_config.py | 11 +++++++++-- 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/infrahub_sdk/batch.py b/infrahub_sdk/batch.py index 6e9cc1cb0..8ecbfdaec 100644 --- a/infrahub_sdk/batch.py +++ b/infrahub_sdk/batch.py @@ -6,6 +6,8 @@ from dataclasses import dataclass from typing import TYPE_CHECKING, Any +from .constants import DEFAULT_MAX_CONCURRENT_EXECUTION + if TYPE_CHECKING: from .node import InfrahubNode, InfrahubNodeSync @@ -56,7 +58,7 @@ class InfrahubBatch: def __init__( self, semaphore: asyncio.Semaphore | None = None, - max_concurrent_execution: int = 5, + max_concurrent_execution: int = DEFAULT_MAX_CONCURRENT_EXECUTION, return_exceptions: bool = False, ) -> None: self._tasks: list[BatchTask] = [] @@ -88,7 +90,9 @@ async def execute(self) -> AsyncGenerator: class InfrahubBatchSync: - def __init__(self, max_concurrent_execution: int = 5, return_exceptions: bool = False) -> None: + def __init__( + self, max_concurrent_execution: int = DEFAULT_MAX_CONCURRENT_EXECUTION, return_exceptions: bool = False + ) -> None: self._tasks: list[BatchTaskSync] = [] self.max_concurrent_execution = max_concurrent_execution self.return_exceptions = return_exceptions diff --git a/infrahub_sdk/config.py b/infrahub_sdk/config.py index 652ee63f7..7d23d75e3 100644 --- a/infrahub_sdk/config.py +++ b/infrahub_sdk/config.py @@ -9,7 +9,7 @@ from pydantic_settings import BaseSettings, InitSettingsSource, PydanticBaseSettingsSource, SettingsConfigDict from typing_extensions import Self -from .constants import InfrahubClientMode, Priority +from .constants import DEFAULT_MAX_CONCURRENT_EXECUTION, InfrahubClientMode, Priority from .playback import JSONPlayback from .recorder import JSONRecorder, NoRecorder, Recorder, RecorderType from .types import AsyncRequester, InfrahubLoggers, RequesterTransport, SyncRequester @@ -54,7 +54,9 @@ class ConfigBase(BaseSettings): ) identifier: str | None = Field(default=None, description="Tracker identifier") insert_tracker: bool = Field(default=False, description="Insert a tracker on queries to the server") - max_concurrent_execution: int = Field(default=5, description="Max concurrent execution in batch mode") + max_concurrent_execution: int = Field( + default=DEFAULT_MAX_CONCURRENT_EXECUTION, description="Max concurrent execution in batch mode" + ) mode: InfrahubClientMode = Field(default=InfrahubClientMode.DEFAULT, description="Default mode for the client") pagination_size: int = Field(default=50, description="Page size for queries to the server") priority: Priority | None = Field( diff --git a/tests/unit/sdk/test_batch.py b/tests/unit/sdk/test_batch.py index da7578094..bb2984b82 100644 --- a/tests/unit/sdk/test_batch.py +++ b/tests/unit/sdk/test_batch.py @@ -1,9 +1,11 @@ from __future__ import annotations +import inspect from typing import TYPE_CHECKING import pytest +from infrahub_sdk.batch import InfrahubBatch, InfrahubBatchSync from infrahub_sdk.constants import DEFAULT_MAX_CONCURRENT_EXECUTION from infrahub_sdk.exceptions import GraphQLError @@ -20,6 +22,16 @@ def test_default_max_concurrent_execution_value() -> None: assert isinstance(DEFAULT_MAX_CONCURRENT_EXECUTION, int) +@pytest.mark.parametrize("batch_class", [InfrahubBatch, InfrahubBatchSync]) +def test_batch_default_max_concurrent_execution(batch_class: type[InfrahubBatch | InfrahubBatchSync]) -> None: + parameter = inspect.signature(batch_class.__init__).parameters["max_concurrent_execution"] + assert parameter.default == DEFAULT_MAX_CONCURRENT_EXECUTION + + +def test_batch_sync_uses_default_max_concurrent_execution() -> None: + assert InfrahubBatchSync().max_concurrent_execution == DEFAULT_MAX_CONCURRENT_EXECUTION + + @pytest.mark.parametrize("client_type", client_types) async def test_batch_execution(clients: BothClients, client_type: str) -> None: r: list[int] = [] diff --git a/tests/unit/sdk/test_config.py b/tests/unit/sdk/test_config.py index 527411276..2645785b2 100644 --- a/tests/unit/sdk/test_config.py +++ b/tests/unit/sdk/test_config.py @@ -4,8 +4,8 @@ import pytest from pydantic import ValidationError -from infrahub_sdk.config import Config -from infrahub_sdk.constants import Priority +from infrahub_sdk.config import Config, ConfigBase +from infrahub_sdk.constants import DEFAULT_MAX_CONCURRENT_EXECUTION, Priority def test_combine_authentications() -> None: @@ -167,3 +167,10 @@ def test_priority_default_is_none() -> None: """With no priority configured, the field defaults to None (no header emitted).""" config = Config(address="http://localhost:8000") assert config.priority is None + + +def test_config_default_max_concurrent_execution(monkeypatch: pytest.MonkeyPatch) -> None: + monkeypatch.delenv("INFRAHUB_MAX_CONCURRENT_EXECUTION", raising=False) + + assert ConfigBase.model_fields["max_concurrent_execution"].default == DEFAULT_MAX_CONCURRENT_EXECUTION + assert Config().max_concurrent_execution == DEFAULT_MAX_CONCURRENT_EXECUTION From b001c203cf38a2b84863689cf69dde1733cd4de7 Mon Sep 17 00:00:00 2001 From: Saltaferis Dimitrios Date: Wed, 2 Dec 2026 10:20:31 +0000 Subject: [PATCH 3/4] chore(changelog): add DEFAULT_MAX_CONCURRENT_EXECUTION fragment Co-Authored-By: Claude Opus 5.5 --- changelog/+default-max-concurrent-execution.added.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog/+default-max-concurrent-execution.added.md diff --git a/changelog/+default-max-concurrent-execution.added.md b/changelog/+default-max-concurrent-execution.added.md new file mode 100644 index 000000000..31703244f --- /dev/null +++ b/changelog/+default-max-concurrent-execution.added.md @@ -0,0 +1 @@ +The default number of batch tasks that run at the same time, 5, is now available as `DEFAULT_MAX_CONCURRENT_EXECUTION` in `infrahub_sdk.constants`. `InfrahubBatch`, `InfrahubBatchSync` and `Config` use it as their default, so code that receives an optional concurrency value can pass `DEFAULT_MAX_CONCURRENT_EXECUTION` when the value is `None` instead of repeating the number 5. From 8f756773afb21a4bdcc636ef90e741610ed75055 Mon Sep 17 00:00:00 2001 From: Saltaferis Dimitrios Date: Wed, 2 Dec 2026 15:01:45 +0000 Subject: [PATCH 4/4] test: drop the tests that pin DEFAULT_MAX_CONCURRENT_EXECUTION Review on #1574 questioned whether they are needed. They compared the constant with 5 and the defaults with the constant, so they would still pass if a literal 5 came back at any default. Co-Authored-By: Claude Opus 5.5 --- tests/unit/sdk/test_batch.py | 18 ------------------ tests/unit/sdk/test_config.py | 11 ++--------- 2 files changed, 2 insertions(+), 27 deletions(-) diff --git a/tests/unit/sdk/test_batch.py b/tests/unit/sdk/test_batch.py index bb2984b82..7bdf00ad9 100644 --- a/tests/unit/sdk/test_batch.py +++ b/tests/unit/sdk/test_batch.py @@ -1,12 +1,9 @@ from __future__ import annotations -import inspect from typing import TYPE_CHECKING import pytest -from infrahub_sdk.batch import InfrahubBatch, InfrahubBatchSync -from infrahub_sdk.constants import DEFAULT_MAX_CONCURRENT_EXECUTION from infrahub_sdk.exceptions import GraphQLError if TYPE_CHECKING: @@ -17,21 +14,6 @@ client_types = ["standard", "sync"] -def test_default_max_concurrent_execution_value() -> None: - assert DEFAULT_MAX_CONCURRENT_EXECUTION == 5 - assert isinstance(DEFAULT_MAX_CONCURRENT_EXECUTION, int) - - -@pytest.mark.parametrize("batch_class", [InfrahubBatch, InfrahubBatchSync]) -def test_batch_default_max_concurrent_execution(batch_class: type[InfrahubBatch | InfrahubBatchSync]) -> None: - parameter = inspect.signature(batch_class.__init__).parameters["max_concurrent_execution"] - assert parameter.default == DEFAULT_MAX_CONCURRENT_EXECUTION - - -def test_batch_sync_uses_default_max_concurrent_execution() -> None: - assert InfrahubBatchSync().max_concurrent_execution == DEFAULT_MAX_CONCURRENT_EXECUTION - - @pytest.mark.parametrize("client_type", client_types) async def test_batch_execution(clients: BothClients, client_type: str) -> None: r: list[int] = [] diff --git a/tests/unit/sdk/test_config.py b/tests/unit/sdk/test_config.py index 2645785b2..527411276 100644 --- a/tests/unit/sdk/test_config.py +++ b/tests/unit/sdk/test_config.py @@ -4,8 +4,8 @@ import pytest from pydantic import ValidationError -from infrahub_sdk.config import Config, ConfigBase -from infrahub_sdk.constants import DEFAULT_MAX_CONCURRENT_EXECUTION, Priority +from infrahub_sdk.config import Config +from infrahub_sdk.constants import Priority def test_combine_authentications() -> None: @@ -167,10 +167,3 @@ def test_priority_default_is_none() -> None: """With no priority configured, the field defaults to None (no header emitted).""" config = Config(address="http://localhost:8000") assert config.priority is None - - -def test_config_default_max_concurrent_execution(monkeypatch: pytest.MonkeyPatch) -> None: - monkeypatch.delenv("INFRAHUB_MAX_CONCURRENT_EXECUTION", raising=False) - - assert ConfigBase.model_fields["max_concurrent_execution"].default == DEFAULT_MAX_CONCURRENT_EXECUTION - assert Config().max_concurrent_execution == DEFAULT_MAX_CONCURRENT_EXECUTION