Skip to content

bug: Upsert fails when using a template due to missing required relationship #7398

@FragmentedPacket

Description

@FragmentedPacket

Component

API Server / GraphQL

Infrahub version

1.4.10

Current Behavior

When using an object file to populate an instance using an object_template that provides one of the required relationships, it fails with: {'message': "Field 'NetworkDeviceUpsertInput.model' of required type 'RelatedNodeInput!' was not provided.", 'locations': [{'line': 4, 'column': 15}]}

---
apiVersion: infrahub.app/v1
kind: Object
spec:
  kind: LogicalNetwork
  data:
    - building: Temp
      num_devices: 4
      devices:
        kind: NetworkDevice
        data:
          - index: 1
            name: temp-switch1
            role: temp_switch
            object_template: Generic switch
          - index: 2
            name: temp-switch2
            role: temp_switch
            object_template: Generic switch
          - index: 3
            name: temp-switch3
            role: temp_switch
            object_template: Generic switch
          - index: 4
            name: temp-switch4
            role: temp_switch
            object_template: Generic switch

Expected Behavior

Ability to add objects that have required attributes that are provided by an object_template

Steps to Reproduce

  1. Use a device schema that has a required relationship to another node such as device model
  2. Attempt to load data via object templates that provide the model

I did have to make a change to SDK code that allowed me to get past the the validations of required/mandatory fields (model): https://github.com/opsmill/infrahub-sdk-python/blob/develop/infrahub_sdk/spec/object.py#L312-L315

        # First validate if all mandatory fields are present
        if "object_template" not in data:
            for element in schema.mandatory_input_names:
                if not any([element in data.keys(), element in context.keys()]):
                    breakpoint()
                    errors.append(ObjectValidationError(position=position + [element], message=f"{element} is mandatory"))

Additional Information

The GraphQL query that is being executed is:

mutation {
    NetworkDeviceUpsert(
        data: {
            role: {
                value: "temp_switch"
            }
            name: {
                value: "temp-switch1"
            }
            index: {
                value: 1
            }
            object_template: {
                hfid: [
                    "Generic switch",
                ]
            }
            logical_network: {
                id: "186e2957-8656-e5ba-328d-c51af5eabad0"
            }
        }
    ){
        ok
        object {
            id
        }
    }
}

Metadata

Metadata

Assignees

Labels

priority/1This issue must be fixed/implemented ASAP, it's a blocker for a releasestate/need-triageThis issue needs to be triagedtype/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