Skip to content

Commit 3f6fa30

Browse files
authored
Merge pull request #982 from opsmill/stable
Merge stable into develop
2 parents 54ba648 + 013341c commit 3f6fa30

4 files changed

Lines changed: 21 additions & 5 deletions

File tree

changelog/908.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Skip mandatory field validation during object loading when `object_profile` is specified.

infrahub_sdk/pytest_plugin/loader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"PythonTransform": "get_python_transform",
3838
}
3939

40-
ITEMS_MAPPING = {
40+
ITEMS_MAPPING: dict[str, type[InfrahubItem]] = {
4141
"check-smoke": InfrahubCheckSmokeItem,
4242
"check-unit-process": InfrahubCheckUnitProcessItem,
4343
"check-integration": InfrahubCheckIntegrationItem,
@@ -71,7 +71,7 @@ def collect_group(self, group: InfrahubTestGroup) -> Iterable[pytest.Item]:
7171
resource_config = self.get_resource_config(group)
7272

7373
for test in group.tests:
74-
item_class: type[pytest.Item] = ITEMS_MAPPING[test.spec.kind] # type: ignore[assignment]
74+
item_class = ITEMS_MAPPING[test.spec.kind]
7575
item: InfrahubItem = item_class.from_parent(
7676
name=f"{marker.markname}__{group.resource_name}__{test.name}",
7777
parent=self,

infrahub_sdk/spec/object.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,9 @@ async def validate_object(
267267
context = context.copy() if context else {}
268268

269269
# First validate if all mandatory fields are present
270-
# Skip mandatory check when an object_template is specified, as the template provides defaults, we expect the API server to just send a
271-
# response with a failure if the template is not valid or doesn't provide all mandatory fields
272-
if "object_template" not in data:
270+
# Skip mandatory check when an object_template or object_profile is specified, as the template/profile provides defaults;
271+
# we expect the API server to return a failure if the template/profile is not valid or doesn't provide all mandatory fields
272+
if "object_template" not in data and "object_profile" not in data:
273273
errors.extend(
274274
ObjectValidationError(position=[*position, element], message=f"{element} is mandatory")
275275
for element in schema.mandatory_input_names

tests/unit/sdk/spec/test_object.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,3 +472,18 @@ async def test_validate_object_skips_mandatory_check_with_object_template(
472472

473473
mandatory_errors = [e for e in errors if e.message == "type is mandatory"]
474474
assert mandatory_errors == []
475+
476+
477+
async def test_validate_object_skips_mandatory_check_with_object_profile(
478+
client_with_schema_01: InfrahubClient,
479+
) -> None:
480+
"""When object_profile is present, mandatory field validation should be skipped."""
481+
schema = await client_with_schema_01.schema.get(kind="BuiltinLocation")
482+
483+
data = {"name": "Site1", "object_profile": "Standard Site"}
484+
errors = await InfrahubObjectFileData.validate_object(
485+
client=client_with_schema_01, position=[1], schema=schema, data=data
486+
)
487+
488+
mandatory_errors = [e for e in errors if e.message == "type is mandatory"]
489+
assert mandatory_errors == []

0 commit comments

Comments
 (0)