Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: Frontend error when accessing Node after deleting a related node in a relationship attribute #5619

Open
BeArchiTek opened this issue Jan 30, 2025 · 0 comments
Labels
priority/2 This issue stalls work on the project or its dependents, it's a blocker for a release state/backlog This issue is part of the backlog type/bug Something isn't working as expected

Comments

@BeArchiTek
Copy link
Contributor

Component

API Server / GraphQL, Frontend UI

Infrahub version

1.1.5

Current Behavior

After deleting a related node assigned to a Device (e.g., an IP address), the frontend attempts to access properties of the now-null relationship, leading to an error.

The frontend sends the following GraphQL query, which includes the properties field of primary_relation even when the related node is deleted:

query DcimDevice {
  DcimDevice(ids: ["181f6b51-9fef-11e6-32b9-c514e30300e9"]) {
    edges {
      node {
        id
        hfid
        display_label
        profiles {
          edges {
            node {
              display_label
              id
              profile_priority {
                value
                __typename
              }
              __typename
            }
            __typename
          }
          __typename
        }
        name {
          id
          value
          updated_at
          is_default
          is_from_profile
          is_protected
          is_visible
          source {
            id
            display_label
            __typename
          }
          owner {
            id
            display_label
            __typename
          }
          __typename
        }
        primary_relation {
          node {
            id
            display_label
            __typename
          }
          properties {
            updated_at
            is_protected
            is_visible
            source {
              id
              display_label
              __typename
            }
            owner {
              id
              display_label
              __typename
            }
            __typename
          }
          __typename
        }
        __typename
      }
      __typename
    }
    __typename
  }
}

Resulting in

"errors": [
  {
    "message": "'181f6b50-b2b9-3db8-32bc-c51bad7209e5'",
    "locations": [
      {
        "line": 43,
        "column": 9
      }
    ],
    "path": [
      "DcimDevice",
      "edges",
      0,
      "node",
      "primary_relation"
    ]
  }
]

It seems like removing the properties field from the GraphQL query (for the ip_address) resolves the issue.

Expected Behavior

The frontend should handle the null primary_relation gracefully without crashing.

Steps to Reproduce

Bug: Frontend Crashes When Accessing Device After Deleting a Related Node

Description

After deleting a related node assigned to a Device (e.g., an IP address), the frontend attempts to access properties of the now-null relationship, leading to an error.

Steps to Reproduce

  1. Start Infrahub 1.1.5

  2. Load the following schema:

    ---

yaml-language-server: $schema=https://schema.infrahub.app/infrahub/schema/latest.json

version: "1.0"

generics:

  • name: GenericDevice
    namespace: Dcim
    include_in_menu: true
    human_friendly_id:
    • name__value
      order_by:
    • name__value
      display_labels:
    • name__value
      attributes:
    • name: name
      kind: Text
      unique: true
      order_weight: 1000
      relationships:
    • name: primary_address
      peer: IpamIPAddress
      label: Primary IP Address
      identifier: genericdevice__ipaddress
      optional: true
      cardinality: one
      kind: Attribute
      order_weight: 1700

nodes:

  • name: IPAddress
    namespace: Ipam
    include_in_menu: true
    display_labels:

    • address__value
      inherit_from:
    • BuiltinIPAddress
      uniqueness_constraints:
    • [ip_namespace, address__value]
      human_friendly_id:
    • address__value
    • ip_namespace__name__value
      attributes:
    • name: fqdn
      label: FQDN
      kind: Text
      optional: true
  • name: Device
    namespace: Dcim
    include_in_menu: true
    inherit_from:

    • DcimGenericDevice
      attributes: []
      relationships: []

3. Create an instance of SomeNode (e.g., example-node)
4. Create a Device (e.g., device1) and assign SomeNode as its primary_relation
5. Delete the assigned SomeNode
6. Try to access the detailed view of the Device


### Additional Information

I flagged the issue as both frontend and backend as :
- maybe the frontend should not request properties if there is no related node
- the backend should not send an error for it
@BeArchiTek BeArchiTek added type/bug Something isn't working as expected group/backend Issue related to the backend (API Server, Git Agent) group/frontend Issue related to the frontend (React) labels Jan 30, 2025
@exalate-issue-sync exalate-issue-sync bot added state/backlog This issue is part of the backlog priority/2 This issue stalls work on the project or its dependents, it's a blocker for a release and removed group/backend Issue related to the backend (API Server, Git Agent) group/frontend Issue related to the frontend (React) labels Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority/2 This issue stalls work on the project or its dependents, it's a blocker for a release state/backlog This issue is part of the backlog type/bug Something isn't working as expected
Projects
None yet
Development

No branches or pull requests

1 participant