diff --git a/CHANGELOG.md b/CHANGELOG.md index 218e0228..1988a9e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,12 @@ This project uses [*towncrier*](https://towncrier.readthedocs.io/) and the chang +## [1.15.1](https://github.com/opsmill/infrahub-sdk-python/tree/v1.15.1) - 2025-11-13 + +### Fixed + +- Fixed nested object template range expansion. ([#624](https://github.com/opsmill/infrahub-sdk-python/issues/624)) + ## [1.15.0](https://github.com/opsmill/infrahub-sdk-python/tree/v1.15.0) - 2025-11-10 ### Added diff --git a/infrahub_sdk/spec/object.py b/infrahub_sdk/spec/object.py index 3bc738c3..77a0babf 100644 --- a/infrahub_sdk/spec/object.py +++ b/infrahub_sdk/spec/object.py @@ -209,6 +209,7 @@ async def process(self, client: InfrahubClient, branch: str | None = None) -> No position=[idx + 1], branch=branch, default_schema_kind=self.kind, + parameters=self.parameters, ) @classmethod @@ -458,7 +459,6 @@ async def create_node( data=value, branch=branch, default_schema_kind=default_schema_kind, - parameters=parameters, ) clean_data[key] = nodes[0] @@ -470,7 +470,9 @@ async def create_node( data=value, branch=branch, default_schema_kind=default_schema_kind, - parameters=parameters, + parameters=InfrahubObjectParameters(**value.get("parameters")) + if "parameters" in value + else None, ) clean_data[key] = nodes @@ -509,7 +511,9 @@ async def create_node( context=context, branch=branch, default_schema_kind=default_schema_kind, - parameters=parameters, + parameters=InfrahubObjectParameters(**data[rel].get("parameters")) + if "parameters" in data[rel] + else None, ) return node diff --git a/pyproject.toml b/pyproject.toml index f06a8d82..f1027051 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "infrahub-sdk" -version = "1.15.0" +version = "1.15.1" description = "Python Client to interact with Infrahub" authors = [ {name = "OpsMill", email = "info@opsmill.com"} diff --git a/tests/unit/sdk/spec/test_object.py b/tests/unit/sdk/spec/test_object.py index 570f14c5..1af02ac3 100644 --- a/tests/unit/sdk/spec/test_object.py +++ b/tests/unit/sdk/spec/test_object.py @@ -100,6 +100,24 @@ def location_expansion_multiple_ranges_bad_syntax(root_location: dict) -> dict: return location +@pytest.fixture +def location_with_non_dict_parameters(root_location: dict) -> dict: + data = [{"name": "Mexico", "type": "Country"}] + location = root_location.copy() + location["spec"]["data"] = data + location["spec"]["parameters"] = "not_a_dict" + return location + + +@pytest.fixture +def location_with_empty_parameters(root_location: dict) -> dict: + data = [{"name": "Mexico", "type": "Country"}] + location = root_location.copy() + location["spec"]["data"] = data + location["spec"]["parameters"] = {} + return location + + async def test_validate_object(client: InfrahubClient, schema_query_01_data: dict, location_mexico_01) -> None: client.schema.set_cache(schema=schema_query_01_data, branch="main") obj = ObjectFile(location="some/path", content=location_mexico_01) @@ -221,3 +239,27 @@ async def test_get_relationship_info_tags( rel_info = await get_relationship_info(client_with_schema_01, location_schema, "tags", data) assert rel_info.is_valid == is_valid assert rel_info.format == format + + +async def test_parameters_top_level(client_with_schema_01: InfrahubClient, location_expansion) -> None: + obj = ObjectFile(location="some/path", content=location_expansion) + await obj.validate_format(client=client_with_schema_01) + assert obj.spec.parameters.expand_range is True + + +async def test_parameters_missing(client_with_schema_01: InfrahubClient, location_mexico_01) -> None: + obj = ObjectFile(location="some/path", content=location_mexico_01) + await obj.validate_format(client=client_with_schema_01) + assert hasattr(obj.spec.parameters, "expand_range") + + +async def test_parameters_empty_dict(client_with_schema_01: InfrahubClient, location_with_empty_parameters) -> None: + obj = ObjectFile(location="some/path", content=location_with_empty_parameters) + await obj.validate_format(client=client_with_schema_01) + assert hasattr(obj.spec.parameters, "expand_range") + + +async def test_parameters_non_dict(client_with_schema_01: InfrahubClient, location_with_non_dict_parameters) -> None: + obj = ObjectFile(location="some/path", content=location_with_non_dict_parameters) + with pytest.raises(ValidationError): + await obj.validate_format(client=client_with_schema_01)