Skip to content

bug: Creating an object with an object template with optional attributes fails to set the optional attributes #630

@minitriga

Description

@minitriga

Component

Python SDK

Infrahub SDK version

1.15.1

Current Behavior

Currently if you have a optional relationship of cardinality one and try to use the object templates the SDK will provide an override value to the backend this causes the backend not to apply the value provided by object template.

The UI provides a mutation like so:

mutation {
  DcimDeviceCreate(
    data: {object_template: {id: "18779f71-9564-3911-3bc2-1065c8cd8363"}, name: {value: "123123"}, location: {id: "18779f71-e8aa-55c1-3bc0-1065ebd40353"}}
  ) {
    object {
      id
      display_label
      hfid
      __typename
    }
    __typename
  }
}

However the SDK would provide a graphql mutation which looks like the following:

mutation {
    DcimDeviceUpsert(
        data: {
            status: {
                value: "active"
            }
            name: {
                value: "123123"
            }
            index: {
                value: 1
            }
            mlag_domain: null
            object_template: {
                id: "18779f71-55f1-390f-3bcf-10652e6ca9d3"
            }
            platform: {
                id: "test"
            }
            primary_address: null
            location: {
                id: "18779f72-1586-2058-3bc3-106527497af8"
            }
            device_type: null
        }
    ){
        ok
        object {
            id
        }
    }
}

You can see there are many null fields being passed in. This also happens when using object files to load data.

Expected Behavior

I would expect optional fields to be ignored and not instantiated by the client when creating a node the backend does not require them so no need to include them.

Steps to Reproduce

  1. Load infrahub with the base schema from the Schema library https://github.com/opsmill/schema-library/blob/main/base/dcim.yml#L87
  2. Create some manufactures and device_types
  3. Create a device type using an object file
---
apiVersion: infrahub.app/v1
kind: Object
spec:
  kind: DcimDevice
  data:
    # Paris HQ Building - Cisco Core Routers
    - name: CoreRouter1
      object_template: CISCO-ASR1006-CORE
      location: hq-01
      status: active
      index: 1
    - name: CoreRouter2
      object_template: CISCO-ASR1006-CORE
      location: hq-01
      status: active
      index: 2

Additional Information

No response

Metadata

Metadata

Assignees

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