Skip to content

bug: Upsert mutation fails when one side of the relationship is optional #7905

@BaptisteGi

Description

@BaptisteGi

Component

Python SDK, API Server / GraphQL

Infrahub version

1.5.3

Current Behavior

When editing some data I get a upsert mutation exception ['LocationBuildingUpsert'] Node 1881bea1-7db4-f69f-3f7b-132df76881cc has -1 peers for stuff__building, no fewer than 1 allowed

Even tho the exception is raised, the data is still edited in the database, creating inconsistent data.

Expected Behavior

I except the mutation to fail and NOT EDIT data.

Steps to Reproduce

  • Load the following schema
---
version: "1.0"

nodes:
  - name: Building
    namespace: Location
    icon: mdi:office-building
    include_in_menu: true
    human_friendly_id:
      - name__value
    display_label: name__value
    attributes:
      - name: name
        kind: Text
        unique: true

  - name: Stuff
    namespace: Random
    display_label: name__value
    human_friendly_id:
      - name__value
    attributes:
      - name: name
        kind: Text
        unique: true
    relationships:
      - name: building
        kind: Attribute
        peer: LocationBuilding
        cardinality: one
        optional: false
        identifier: stuff__building

extensions:
  nodes:
    - kind: LocationBuilding
      relationships:
        - name: stuff
          kind: Attribute
          peer: RandomStuff
          cardinality: one
          optional: true
          identifier: stuff__building
  • Then load the current object file multiple times
---
apiVersion: infrahub.app/v1
kind: Object
spec:
  kind: LocationBuilding
  data:
    - name: BigBuilding

---
apiVersion: infrahub.app/v1
kind: Object
spec:
  kind: RandomStuff
  data:
    - name: FirstStuff
      building: BigBuilding

-> Raises this exception every other time

infrahubctl object load objects.yml
['LocationBuildingUpsert'] Node 1881bea1-7db4-f69f-3f7b-132df76881cc has -1 peers for stuff__building, no fewer than 1 allowed

-> After the failure you can see RandomStuff records in the database WITHOUT relationship to building, even tho it's a mandatory field

Additional Information

  • The same behavior is present using frontend as well
  • This prevents object files to be properly loaded using GIT integration

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority/1This issue must be fixed/implemented ASAP, it's a blocker for a releasetype/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