Skip to content

Schema: schema load fails when referencing a generate_template-derived node from a co-loaded schema #9364

Description

@minitriga

Component

API Server / GraphQL

Infrahub version

unknown (server unreachable at time of report)

Current Behavior

When loading a directory of schema files with infrahubctl schema load <dir>, the
load fails if:

  1. One file defines a node with generate_template: true (e.g. DcimDevice)
  2. Another file in the same load batch references the auto-generated template node
    as a relationship peer (e.g. peer: TemplateDcimDevice)

Error:

Unable to load the schema:
  Unable to find the schema 'TemplateDcimDevice' in the registry

The auto-generated TemplateDcimDevice node does not yet exist in the registry at
validation time — it would only be created as a by-product of loading the schema
that carries generate_template: true. The validator checks peer node existence
before that generation step runs, so the two schemas can never be loaded together.

Expected Behavior

When a co-loaded schema defines a node with generate_template: true, the
validator should recognise that Template<Namespace><Name> will exist after
loading, and allow other schemas in the same batch to reference that node as a
relationship peer.

Steps to Reproduce

  1. Create schemas/base/dcim.yml with a node that has generate_template: true:
nodes:
  - name: Device
    namespace: Dcim
    generate_template: true
    # ... other attributes
  1. Create schemas/otn.yml with a node that references the generated template:
nodes:
  - name: DesignDeviceEntry
    namespace: Otn
    relationships:
      - name: template
        peer: TemplateDcimDevice   # auto-generated from DcimDevice
        kind: Attribute
        cardinality: one
  1. Run infrahubctl schema load schemas
  2. Observe: Unable to find the schema 'TemplateDcimDevice' in the registry

Additional Information

The generated node name follows the pattern Template<Namespace><NodeName>, so
DcimDevice with generate_template: true produces TemplateDcimDevice. This
naming is documented and expected, but the schema batch loader does not account
for it during peer validation.

Related: #6836 (template creation forces parent template) — same category of
issue where template node generation order creates unexpected constraints.

Environment

  • infrahub-sdk: v1.20.1
  • Python: 3.12.11
  • OS: macOS arm64

Metadata

Metadata

Assignees

No one assigned

    Labels

    state/need-triageThis issue needs to be triagedtype/bugSomething isn't working as expected

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions