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: Unhandled exception when loading menu in a branch if it exists in main #5473

Open
BeArchiTek opened this issue Jan 15, 2025 · 0 comments
Assignees
Labels
group/backend Issue related to the backend (API Server, Git Agent) type/bug Something isn't working as expected
Milestone

Comments

@BeArchiTek
Copy link
Contributor

Component

API Server / GraphQL

Infrahub version

1.1.2

Current Behavior

After loading a menu file in main I am trying to load it in a branch created beforehand.
When loading it in the branch, I got an error with infrahubctl :

['CoreMenuItemUpsert'] Violates uniqueness constraint 'namespace-name' at namespace, Violates uniqueness constraint 'namespace-name' at name

and see this in the servers logs :

2025-01-15T12:56:42.726021Z [critical ] Unhandled exception occurred in resolvers [infrahub.graphql] app=infrahub.api request_id=a19bedada052475e96d2456cd8948772 worker=79449b96-c30e-4fbe-9254-1e7553ffc448
Traceback (most recent call last):
  File "/source/backend/infrahub/graphql/mutations/main.py", line 188, in mutate_create_object
    await node_constraint_runner.check(node=obj, field_filters=fields_to_validate)
  File "/source/backend/infrahub/core/constraint/node/runner.py", line 31, in check
    await node_constraint.check(node, filters=field_filters)
  File "/source/backend/infrahub/core/node/constraints/grouped_uniqueness.py", line 181, in check
    await self._check_one_schema(node=node, node_schema=schema, at=at, filters=filters)
  File "/source/backend/infrahub/core/node/constraints/grouped_uniqueness.py", line 170, in _check_one_schema
    await self._check_results(updated_node=node, path_groups=path_groups, query_results=query.get_results())
  File "/source/backend/infrahub/core/node/constraints/grouped_uniqueness.py", line 148, in _check_results
    self._check_one_constraint_group(
  File "/source/backend/infrahub/core/node/constraints/grouped_uniqueness.py", line 133, in _check_one_constraint_group
    raise ValidationError(errors)
infrahub.exceptions.ValidationError: Violates uniqueness constraint 'namespace-name' at namespace, Violates uniqueness constraint 'namespace-name' at name

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/graphql/execution/execute.py", line 530, in await_result
    return_type, field_nodes, info, path, await result
                                          ^^^^^^^^^^^^
  File "/source/backend/infrahub/graphql/mutations/main.py", line 79, in mutate
    obj, mutation, created = await cls.mutate_upsert(
                             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/source/backend/infrahub/database/__init__.py", line 498, in wrapper
    return await func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/source/backend/infrahub/graphql/mutations/main.py", line 348, in mutate_upsert
    created_obj, mutation = await cls.mutate_create(info=info, data=data_dict, branch=branch)
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/source/backend/infrahub/graphql/mutations/menu.py", line 60, in mutate_create
    obj, result = await super().mutate_create(info=info, data=data, branch=branch)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/source/backend/infrahub/graphql/mutations/main.py", line 166, in mutate_create
    obj = await cls._call_mutate_create_object(data=data, db=db, branch=branch)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/source/backend/infrahub/graphql/mutations/main.py", line 154, in _call_mutate_create_object
    return await cls.mutate_create_object(data=data, db=db, branch=branch)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/source/backend/infrahub/database/__init__.py", line 498, in wrapper
    return await func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/source/backend/infrahub/graphql/mutations/main.py", line 196, in mutate_create_object
    raise ValueError(str(exc)) from exc
ValueError: Violates uniqueness constraint 'namespace-name' at namespace, Violates uniqueness constraint 'namespace-name' at name

Expected Behavior

Exception gracefully handled in the server, and reported

Steps to Reproduce

  • Start infrahub
  • Create a test branch withinfrahubctl branch create test
  • Add menu Items in main with infrahubctl menu load models/base_menu.yml
  • Add menu Items in test with infrahubctl menu load models/base_menu.yml --branch test

Additional Information

No response

@BeArchiTek BeArchiTek added the type/bug Something isn't working as expected label Jan 15, 2025
@BeArchiTek BeArchiTek changed the title bug: Unhandled exception when loading menu in a branch bug: Unhandled exception when loading menu in a branch if it exists in main Jan 15, 2025
@BeArchiTek BeArchiTek added the group/backend Issue related to the backend (API Server, Git Agent) label Jan 15, 2025
@dgarros dgarros added this to the Backlog milestone Jan 15, 2025
@dgarros dgarros self-assigned this Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
group/backend Issue related to the backend (API Server, Git Agent) type/bug Something isn't working as expected
Projects
None yet
Development

No branches or pull requests

2 participants