Skip to content

bug: Object file validation requires mandatory attributes even when a profile provides them #908

@dgarros

Description

@dgarros

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

  1. Create a profile that provides values for mandatory attributes of a given kind
  2. Create an object file that references that profile via object_profile
  3. Omit the mandatory attributes from the object file data (since the profile provides them)
  4. Run infrahubctl object validate on the object file
  5. Validation fails with <attribute> is mandatory errors

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/bugSomething isn't working as expected

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions