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: Invalid schema after renaming schema nodes #4909

Closed
ogenstad opened this issue Nov 11, 2024 · 0 comments · Fixed by #4915
Closed

bug: Invalid schema after renaming schema nodes #4909

ogenstad opened this issue Nov 11, 2024 · 0 comments · Fixed by #4915
Assignees
Labels
group/backend Issue related to the backend (API Server, Git Agent) group/schema Issue related to some schemas type/bug Something isn't working as expected

Comments

@ogenstad
Copy link
Contributor

Component

API Server / GraphQL

Infrahub version

v1.1.0-dev

Current Behavior

When you rename a schema node problems within the GraphQL schema. This can be observed in the temporary PR #4908, which fails the test TestSchemaLifecycleMain::test_step03_load

It's also now confirmed to be an actual problem that would impact you after you renamed a schema node, or at least "took over" another one that is the case here.

When running using gunicorn the issue doesn't always appear it comes and goes, if you just run "infrahub server" the issue seems to always appear. This indicates that the problem only exists on the worker that was responsible for the schema load.

Expected Behavior

This shouldn't cause an issue

Steps to Reproduce

  1. Start a new instance of Infrahub
  2. Paste the below code in snippets into a Python terminal, load the initial schema:

Load the initial schema

from infrahub_sdk import InfrahubClientSync

client = InfrahubClientSync()

initial_schema = {
    "version": "1.0",
    "nodes": [
        {
            "name": "Person",
            "namespace": "Testing",
            "include_in_menu": True,
            "label": "Person",
            "attributes": [
                {"name": "name", "kind": "Text"},
                {"name": "description", "kind": "Text", "optional": True},
                {"name": "height", "kind": "Number", "optional": True},
            ],
            "relationships": [
                {"name": "cars", "kind": "Generic", "optional": True, "peer": "TestingCar", "cardinality": "many"}
            ],
        },
        {
            "name": "Car",
            "namespace": "Testing",
            "include_in_menu": True,
            "default_filter": "name__value",
            "label": "Car",
            "attributes": [
                {"name": "name", "kind": "Text"},
                {"name": "description", "kind": "Text", "optional": True},
                {"name": "color", "kind": "Text"},
            ],
            "relationships": [
                {
                    "name": "owner",
                    "kind": "Attribute",
                    "optional": False,
                    "peer": "TestingPerson",
                    "cardinality": "one",
                },
                {
                    "name": "manufacturer",
                    "kind": "Attribute",
                    "optional": False,
                    "peer": "TestingManufacturer",
                    "cardinality": "one",
                    "identifier": "car__manufacturer",
                },
            ],
        },
        {
            "name": "Manufacturer",
            "namespace": "Testing",
            "include_in_menu": True,
            "label": "Manufacturer",
            "attributes": [{"name": "name", "kind": "Text"}, {"name": "description", "kind": "Text", "optional": True}],
            "relationships": [
                {
                    "name": "cars",
                    "kind": "Generic",
                    "optional": True,
                    "peer": "TestingCar",
                    "cardinality": "many",
                    "identifier": "car__manufacturer",
                },
                {
                    "name": "customers",
                    "kind": "Generic",
                    "optional": True,
                    "peer": "TestingPerson",
                    "cardinality": "many",
                    "identifier": "person__manufacturer",
                },
            ],
        },
        {
            "name": "Tag",
            "namespace": "Testing",
            "include_in_menu": True,
            "label": "Testing Tag",
            "attributes": [{"name": "name", "kind": "Text"}],
            "relationships": [
                {"name": "cars", "kind": "Generic", "optional": True, "peer": "TestingCar", "cardinality": "many"},
                {
                    "name": "persons",
                    "kind": "Generic",
                    "optional": True,
                    "peer": "TestingPerson",
                    "cardinality": "many",
                },
            ],
        },
    ],
}

client.schema.load(schemas=[initial_schema])
  1. After the schema has converged continue with this snippet
testing_manufacturer = client.schema.get("TestingManufacturer")

step3 = {
    "version": "1.0",
    "nodes": [
        {
            "name": "Person",
            "namespace": "Testing",
            "include_in_menu": True,
            "label": "Person",
            "attributes": [
                {"name": "firstname", "kind": "Text"},
                {"name": "description", "kind": "Text", "optional": True},
                {"name": "height", "kind": "Number", "optional": True, "state": "absent"},
                {"name": "lastname", "kind": "Text", "optional": True},
            ],
            "relationships": [
                {"name": "cars", "kind": "Generic", "optional": True, "peer": "TestingCar", "cardinality": "many"}
            ],
        },
        {
            "name": "Car",
            "namespace": "Testing",
            "include_in_menu": True,
            "default_filter": "name__value",
            "label": "Car",
            "attributes": [
                {"name": "name", "kind": "Text"},
                {"name": "description", "kind": "Text", "optional": True},
                {"name": "color", "kind": "Text"},
            ],
            "relationships": [
                {
                    "name": "owner",
                    "kind": "Attribute",
                    "optional": False,
                    "peer": "TestingPerson",
                    "cardinality": "one",
                },
                {
                    "name": "manufacturer",
                    "kind": "Attribute",
                    "optional": False,
                    "peer": "TestingCarMaker",
                    "cardinality": "one",
                    "identifier": "car__manufacturer",
                },
            ],
        },
        {
            "id": testing_manufacturer.id,
            "name": "CarMaker",
            "namespace": "Testing",
            "include_in_menu": True,
            "label": "CarMaker",
            "attributes": [{"name": "name", "kind": "Text"}, {"name": "description", "kind": "Text", "optional": True}],
            "relationships": [
                {
                    "name": "cars",
                    "kind": "Generic",
                    "optional": True,
                    "peer": "TestingCar",
                    "cardinality": "many",
                    "identifier": "car__manufacturer",
                },
                {
                    "name": "customers",
                    "kind": "Generic",
                    "optional": True,
                    "peer": "TestingPerson",
                    "cardinality": "many",
                    "identifier": "person__manufacturer",
                },
            ],
        },
        {
            "name": "Tag",
            "namespace": "Testing",
            "include_in_menu": True,
            "label": "Testing Tag",
            "attributes": [{"name": "name", "kind": "Text"}],
            "relationships": [
                {"name": "cars", "kind": "Generic", "optional": True, "peer": "TestingCar", "cardinality": "many"},
                {
                    "name": "persons",
                    "kind": "Generic",
                    "optional": True,
                    "peer": "TestingPerson",
                    "cardinality": "many",
                },
            ],
        },
    ],
}


client.schema.load(schemas=[step3])
  1. Trigger the failure

Note that you might need to run it multiple times if you have several workers before the error appears:

client.all(kind="BuiltinTag")

The output from the good condition:

[]

The output from the bad condition:

GraphQLError: An error occurred while executing the GraphQL Query
query {
    BuiltinTag(limit: 50) {
        count
        edges {
            node {
                id
                hfid
                display_label
                __typename
                name {
                    value
                    is_default
                    is_from_profile
                    is_visible
                    is_protected
                    source {
                        id
                        display_label
                        __typename
                    }
                    owner {
                        id
                        display_label
                        __typename
                    }
                }
                description {
                    value
                    is_default
                    is_from_profile
                    is_visible
                    is_protected
                    source {
                        id
                        display_label
                        __typename
                    }
                    owner {
                        id
                        display_label
                        __typename
                    }
                }
            }
        }
    }
}
, [{'message': "Unable to find the schema 'TestingManufacturer' in the registry", 'extensions': {'code': 422}}]

Additional Information

Temporary workaround: The issue should clear up after a restart of the server

@ogenstad ogenstad added type/bug Something isn't working as expected group/backend Issue related to the backend (API Server, Git Agent) labels Nov 11, 2024
@dgarros dgarros added this to the Infrahub - 1.0.x milestone Nov 11, 2024
@dgarros dgarros added the group/schema Issue related to some schemas label Nov 11, 2024
@ogenstad ogenstad self-assigned this Nov 12, 2024
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) group/schema Issue related to some schemas type/bug Something isn't working as expected
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants