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: parent, children, ancestors and descendants should be added to the restricted attributes and relationship names #6125

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

Comments

@wvandeun
Copy link
Contributor

Component

No response

Infrahub version

1.2.0

Current Behavior

You can define a schemanode with one of the following names or attributes: parent, children, ancestors and descendants. These relationship names are used internally for hierarchical nodes and should be restricted.

Expected Behavior

A user should not be allowed to create relationships or attributes with the name parent/children/ancestors/descendants.

Steps to Reproduce

  • spin up instance of Infrahub
  • load this schema
---
version: "1.0"
generics:
  - name: Location
    namespace: Generic
    hierarchical: true
    attributes:
      - name: name
        unique: true
        optional: false
        kind: Text
nodes:
  - name: Site
    namespace: Location
    inherit_from:
      - GenericLocation
    children: "TestingParent"
    parent: ""

  - name: Parent
    namespace: Testing
    inherit_from:
      - GenericLocation
    children: ""
    parent: LocationSite
    relationships:
      - name: children
        kind: Generic
        optional: true
        peer: TestingChild
        cardinality: many

  - name: Child
    namespace: Testing
    attributes:
      - name: name
        unique: true
        optional: false
        kind: Text
    relationships:
      - name: parent
        kind: Attribute
        optional: false
        peer: TestingParent
        cardinality: one
  • Create a site node
  • Create a parent node, set the parent to the site
  • Create a child node, set the parent to the parent
  • Navigate to the parent detail view, click on the children tab
  • An error message will show
Fragment cannot be spread here as objects of type 'GenericLocation' can never be of type 'TestingChild'.

Additional Information

Did an attempt to parent/children/ancestors and descendants to RESERVED_ATTR_REL_NAMES but after it the server would not start

RESERVED_ATTR_REL_NAMES = [

{"event": "Traceback (most recent call last):\n  File \"/usr/local/lib/python3.12/site-packages/starlette/routing.py\", line 693, in lifespan\n    async with self.lifespan_context(app) as maybe_state:\n               ^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/usr/local/lib/python3.12/contextlib.py\", line 210, in __aenter__\n    return await anext(self.gen)\n           ^^^^^^^^^^^^^^^^^^^^^\n  File \"/usr/local/lib/python3.12/site-packages/fastapi/routing.py\", line 133, in merged_lifespan\n    async with original_context(app) as maybe_original_state:\n               ^^^^^^^^^^^^^^^^^^^^^\n  File \"/usr/local/lib/python3.12/contextlib.py\", line 210, in __aenter__\n    return await anext(self.gen)\n           ^^^^^^^^^^^^^^^^^^^^^\n  File \"/usr/local/lib/python3.12/site-packages/fastapi/routing.py\", line 133, in merged_lifespan\n    async with original_context(app) as maybe_original_state:\n               ^^^^^^^^^^^^^^^^^^^^^\n  File \"/usr/local/lib/python3.12/contextlib.py\", line 210, in __aenter__\n    return await anext(self.gen)\n           ^^^^^^^^^^^^^^^^^^^^^\n  File \"/source/backend/infrahub/server.py\", line 106, in lifespan\n    await app_initialization(application)\n  File \"/source/backend/infrahub/server.py\", line 91, in app_initialization\n    await initialization(db=db)\n  File \"/source/backend/infrahub/core/initialization.py\", line 131, in initialization\n    await initialize_registry(db=db, initialize=True)\n  File \"/source/backend/infrahub/core/initialization.py\", line 86, in initialize_registry\n    root = await get_root_node(db=db, initialize=initialize)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/source/backend/infrahub/core/initialization.py\", line 47, in get_root_node\n    await first_time_initialization(db=db)\n  File \"/source/backend/infrahub/core/initialization.py\", line 482, in first_time_initialization\n    schema_branch.process()\n  File \"/source/backend/infrahub/core/schema/schema_branch.py\", line 482, in process\n    self.process_validate()\n  File \"/source/backend/infrahub/core/schema/schema_branch.py\", line 499, in process_validate\n    self.validate_names()\n  File \"/source/backend/infrahub/core/schema/schema_branch.py\", line 917, in validate_names\n    raise ValueError(f\"{node.kind}: {rel.name} isn't allowed as a relationship name.\")\nValueError: CoreMenuItem: parent isn't allowed as a relationship name.\n", "timestamp": "2025-03-19T23:30:58.905018Z", "logger": "uvicorn.error", "level": "error"}
@wvandeun wvandeun added the type/bug Something isn't working as expected label Mar 24, 2025
@dgarros dgarros added the group/backend Issue related to the backend (API Server, Git Agent) label Mar 25, 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

3 participants