Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ This project uses [*towncrier*](https://towncrier.readthedocs.io/) and the chang

<!-- towncrier release notes start -->

## [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
Expand Down
10 changes: 7 additions & 3 deletions infrahub_sdk/spec/object.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]

Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "infrahub-sdk"
version = "1.15.0"
version = "1.15.1"
description = "Python Client to interact with Infrahub"
authors = ["OpsMill <[email protected]>"]
readme = "README.md"
Expand Down
42 changes: 42 additions & 0 deletions tests/unit/sdk/spec/test_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)