Skip to content

bug: Test for infrahub-bug-pipeline app #9

@polmichel

Description

@polmichel

Component

API Server / GraphQL

Infrahub version

1.8.4

Current Behavior

I created a schema and leveraged relationship direction and generics to capture my use case. However in some certain situations it's possible for data to slips in and break the relationship cardinality.

In the logs I can see:

Traceback (most recent call last):
  File "/.venv/lib/python3.13/site-packages/graphql/execution/execute.py", line 530, in await_result
    return_type, field_nodes, info, path, await result
                                          ^^^^^^^^^^^^
  File "/.venv/lib/python3.13/site-packages/opentelemetry/util/_decorator.py", line 71, in async_wrapper
    return await func(*args, **kwargs)  # type: ignore
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/source/backend/infrahub/database/__init__.py", line 519, in wrapper
    return await func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/source/backend/infrahub/graphql/resolvers/resolver.py", line 242, in default_paginated_list_resolver
    objs = await NodeManager.query(
           ^^^^^^^^^^^^^^^^^^^^^^^^
    ...<11 lines>...
    )
    ^
  File "/source/backend/infrahub/core/manager.py", line 190, in query
    response = await cls.get_many(
               ^^^^^^^^^^^^^^^^^^^
    ...<8 lines>...
    )
    ^
  File "/source/backend/infrahub/core/manager.py", line 1188, in get_many
    await cls._enrich_node_dicts_with_relationships(
    ...<8 lines>...
    )
  File "/source/backend/infrahub/core/manager.py", line 1266, in _enrich_node_dicts_with_relationships
    await cls._enrich_one_node_with_relationships(
    ...<6 lines>...
    )
  File "/source/backend/infrahub/core/manager.py", line 1316, in _enrich_one_node_with_relationships
    raise ValueError("At most, one relationship expected")
ValueError: At most, one relationship expected

Expected Behavior

I expect that the backend throw me off while trying to add a second edge to a relationship with cardinality one.

Steps to Reproduce

  • Spin infrahub
  • Load this schema
---
# yaml-language-server: $schema=https://schema.infrahub.app/infrahub/schema/latest.json
version: "1.0"

nodes:
  - name: UnicastIPAddress
    namespace: Network
    inherit_from:
      - BuiltinIPAddress
    relationships:
      - name: layer3
        peer: InterfaceLayer3
        kind: Generic
        optional: true
        cardinality: one
        identifier: ip__l3interface
        direction: inbound

  - name: AnycastIPAddress
    namespace: Network
    inherit_from:
      - BuiltinIPAddress
    relationships:
      - name: layer3
        peer: InterfaceLayer3
        kind: Generic
        optional: true
        cardinality: many
        identifier: ip__l3interface
        direction: inbound

  - name: Layer3
    namespace: Interface
    attributes:
      - name: name
        kind: Text
        unique: true
    relationships:
      - name: ip_addresses
        peer: BuiltinIPAddress
        kind: Attribute
        optional: true
        cardinality: many
        identifier: ip__l3interface
        direction: outbound
  • Using the UI create one UnicastIPAddress record
  • Then create a first Layer3 record that point toward the previously created IP
  • Repeat that operation

=> This effectively added two interfaces to the UnicastIPAddress record even tho only one should be allowed. Going back to the IPAM module the interface should crash with the above message.

Additional Information

I can't say it for sure but I haven't managed to reproduce the issue without using the BuiltinIPAddress generic. It doesn't seem to produce the same issue using a different generic...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions