Skip to content

bug: member_of_groups on an Object Template applies to the template itself and is not inherited by instances #9094

@FragmentedPacket

Description

@FragmentedPacket

Component

API Server / GraphQL

Infrahub version

1.8.6 and 1.9.0

Current Behavior

When a member_of_groups relationship is configured on an Object Template, two unexpected things happen:

  1. The template node itself becomes a member of the referenced group as soon as the template is saved.
  2. Objects subsequently created from that template do not inherit the group membership — the group relationship is silently dropped.

Effectively, member_of_groups set on a template applies to the template, never to its instances.

Confirmed in source:

  • add_groups() in backend/infrahub/core/schema/schema_branch.py injects a member_of_groups relationship into nearly every node kind. Templates are not excluded, so setting member_of_groups on a template literally adds the template node to that real group.

  • Template instantiation in backend/infrahub/templates/node_applier.py only propagates relationships whose kind is ATTRIBUTE, GENERIC, or PROFILE:

    if rel_schema.kind not in [RelationshipKind.ATTRIBUTE, RelationshipKind.GENERIC, RelationshipKind.PROFILE]:
        continue

    member_of_groups is registered with kind=RelationshipKind.GROUP, so it is skipped at instantiation time.

Expected Behavior

Configuring member_of_groups on an Object Template should express intent for the resulting instances, not for the template itself. Specifically:

  • Setting member_of_groups on a template should not add the template node to the group.
  • Each object created from the template should be added as a member of the configured group(s) automatically at creation time.

This is structurally the same problem as #6551 (selecting a resource pool on a template allocated a resource to the template instead of to instances). Resolving it consistently with that precedent — e.g. a template-side field that drives per-instance group membership — would be ideal.

Steps to Reproduce

  1. Spin up an Infrahub instance.

  2. Load a schema with a node that has generate_template: true, e.g.:

    version: "1.0"
    nodes:
      - name: Device
        namespace: Infra
        generate_template: true
        attributes:
          - name: name
            kind: Text
            unique: true
  3. Create a CoreStandardGroup (e.g. staged_devices).

  4. Create an object template for InfraDevice and add staged_devices to its member_of_groups.

  5. Inspect the group: the template node is listed as a member. (Behavior 1)

  6. Create a new InfraDevice from that template.

  7. Inspect the new device's member_of_groups and the staged_devices group: the new device is not a member. (Behavior 2)

Additional Information

  • Related/precedent: bug: selecting a resource pool in an object template allocates a resource to the template #6551 (resource pool on template allocated to template, not instance — same shape, fixed via a template-side <rel>_from_resource_pool field).
  • Source references in current develop:
    • backend/infrahub/core/schema/schema_branch.pyadd_groups() (~line 2195)
    • backend/infrahub/templates/node_applier.py_apply_relationships() (~line 60), specifically the relationship-kind filter (~line 80)
  • Practical impact: event-driven workflows that rely on a CoreGroupTriggerRule firing when a template-instantiated object is added to a group cannot use member_of_groups on the template to drive that membership today; a separate CoreNodeTriggerRule + CoreGroupAction is required as a workaround.

Metadata

Metadata

Assignees

Labels

type/bugSomething isn't working as expected

Type

No type
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