Skip to content

bug: Unable to delete relationship of cardinality one from an InfrahubNode object #479

@FragmentedPacket

Description

@FragmentedPacket

h3. Component

[| #component]

Python SDK

h3. Infrahub SDK version

[| #infrahub-sdk-version]

1.13.3

h3. Current Behavior

[| #current-behavior]

We're unable to remove a relationship from an object that is cardinality of one in the SDK using the returned InfrahubNode.

h3. Expected Behavior

[| #expected-behavior]

We can set a relationship of cardinality one to None to remove the relationship.

h3. Steps to Reproduce

[| #steps-to-reproduce]

Create a Python file with the following code:

from infrahub_sdk import InfrahubClient

# Main function
async def run(
    client: InfrahubClient,
    branch: str,
    log,
) -> None:
    """Cannot delete rel of card one easily."""
    interface = await client.get(kind="InfraInterfaceL2", name__value="Ethernet1", device__name__value="atl1-leaf2")
    interface.lag = None
    await interface.save()

Execute script: INFRAHUB_ECHO_GRAPHQL_QUERIES=true INFRAHUB_ADDRESS=https://demo.infrahub.app infrahubctl run <script_name.py>

This wills how you the GraphQL query that gets sent:

URL: https://demo.infrahub.app/graphql/main
QUERY:

query {
    InfraInterfaceL2(name__value: "Ethernet1", device__name__value: "atl1-leaf2", limit: 50) {
        count
        edges {
            node {
                id
                hfid
                display_label
                __typename
                lacp_rate {
                    value
                }
                l2_mode {
                    value
                }
                lacp_priority {
                    value
                }
                name {
                    value
                }
                description {
                    value
                }
                speed {
                    value
                }
                role {
                    value
                }
                enabled {
                    value
                }
                mtu {
                    value
                }
                status {
                    value
                }
                tagged_vlan {
                    count
                    edges {
                        node {
                            id
                            hfid
                            display_label
                            __typename
                        }
                    }
                }
                untagged_vlan {
                    node {
                        id
                        hfid
                        display_label
                        __typename
                    }
                }
                lag {
                    node {
                        id
                        hfid
                        display_label
                        __typename
                    }
                }
                device {
                    node {
                        id
                        hfid
                        display_label
                        __typename
                    }
                }
                tags {
                    count
                    edges {
                        node {
                            id
                            hfid
                            display_label
                            __typename
                        }
                    }
                }
                connected_endpoint {
                    node {
                        id
                        hfid
                        display_label
                        __typename
                    }
                }
            }
        }
    }
}

URL: https://demo.infrahub.app/graphql/main
QUERY:

mutation {
    InfraInterfaceL2Update(
        data: {
            id: "1808d332-74b5-84be-d0e0-c516b7f02953"
        }
    ){
        ok
        object {
            id
        }
    }
}

Check UI and see the LAG still exists

h3. Additional Information

[| #additional-information]

No response

Metadata

Metadata

Assignees

Labels

type/bugSomething isn't working as expected

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions