Skip to content

bug: object get YAML output is not loadable by object load (many relationships exported as invalid nested data dict) #1274

Description

@lancamat1

Component

infrahubctl

Infrahub SDK version

1.23.0

Current Behavior

The YAML produced by infrahubctl object get <kind> --output yaml cannot be fed back into infrahubctl object load.

For cardinality-many relationships, the YAML formatter exports peer references wrapped in a nested dict:

---
apiVersion: infrahub.app/v1
kind: Object
spec:
  kind: TestingGadget
  data:
  - name: multitool
    tags:
      data:
      - red
      - blue

object load accepts two formats for a many relationship: a plain list of HFIDs, or a data: list of dicts describing nested objects. A data: list of HFID strings matches neither, so loading fails validation:

1.tags: Relationship tags doesn't have the right format many / <class 'dict'>

Any kind with a populated Attribute-kind many relationship (for example tags) is affected, because those relationships are fetched by default by object get and always end up in the exported YAML.

Expected Behavior

The output of object get --output yaml should be directly loadable by object load, e.g. infrahubctl object get InfraDevice --output yaml > backup.yml && infrahubctl object load backup.yml should work. The object get help text even shows the > backup.yml workflow, and the formatter docstring states the output is round-trippable.

Steps to Reproduce

  1. Load a schema with a many relationship of kind Attribute (e.g. a node with tags pointing to BuiltinTag).
  2. Create two tags and one object referencing them.
  3. infrahubctl object get TestingGadget --output yaml > gadgets.yml
  4. infrahubctl object load gadgets.yml → fails with the error above.

Reproduced end-to-end with infrahub-testcontainers; the failing round-trip is covered by an integration test (object get → file → object load).

Additional Information

  • Origin: YamlFormatter._node_to_data_entry (infrahub_sdk/ctl/formatters/yaml.py, the many-relationship branch) emits {"data": [<hfids>]}; get_relationship_info (infrahub_sdk/spec/object.py) leaves such a value's format UNKNOWN and validate_related_nodes rejects it.
  • Related but distinct: many relationships of kind Generic are silently omitted from object get output entirely (the SDK only fetches Attribute/Parent-kind many relationships by default), so those never round-trip. Filed separately.

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