-
Notifications
You must be signed in to change notification settings - Fork 7
bug: Object file validation requires mandatory attributes even when a profile provides them #908
Description
Component
- infrahubctl
Infrahub SDK version
Latest (stable)
Current Behavior
When using an object file alongside a profile (object_profile), the infrahubctl object validate and infrahubctl object load commands still require all mandatory attributes to be present in the object file data, even though those attributes are provided by the profile.
This forces users to duplicate attribute values that are already defined in the profile, defeating the purpose of using profiles.
Expected Behavior
When an object_profile is specified in the object file data, mandatory attribute validation should be skipped — the same way it is already skipped when an object_template is specified (added in #895 / commit 5224d24).
Steps to Reproduce
- Create a profile that provides values for mandatory attributes of a given kind
- Create an object file that references that profile via
object_profile - Omit the mandatory attributes from the object file data (since the profile provides them)
- Run
infrahubctl object validateon the object file - Validation fails with
<attribute> is mandatoryerrors
Additional Information
The validation logic in infrahub_sdk/spec/object.py (lines 266-274) currently only skips mandatory checks for object_template:
if "object_template" not in data:
errors.extend(
ObjectValidationError(position=[*position, element], message=f"{element} is mandatory")
for element in schema.mandatory_input_names
if not any([element in data, element in context])
)The fix should extend this check to also skip mandatory validation when object_profile is present in the data, mirroring the approach taken for templates in #895.