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: artifact does not get regenerated when the transformation graphqlquery returns new nodes that are not part of the CoreGraphQLQueryGroup #4198

Closed
wvandeun opened this issue Aug 28, 2024 · 0 comments · Fixed by #4992
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

API Server / GraphQL

Infrahub version

0.16.0.dev0

Current Behavior

Given the following schema

---
version: "1.0"
nodes:
  - name: Interface
    namespace: Infra
    uniqueness_constraints:
      - ["device", "name__value"]
    attributes:
      - name: name
        kind: Text
        optional: false
    relationships:
      - name: device
        peer: InfraDevice
        optional: false
        cardinality: one
        kind: Parent
  - name: Device
    namespace: Infra
    human_friendly_id:
      - "name__value"
    attributes:
      - name: name
        kind: Text
        unique: true
        optional: false
    relationships:
      - name: interfaces
        peer: InfraInterface
        cardinality: many
        optional: true
        kind: Component
  - name: Server
    namespace: Infra
    attributes:
      - name: name
        kind: Text
        optional: false
        unique: true

And the following GraphQLQuery used in a jinja2 transform, for which we have an artifact definition that is imported into Infrahub from a Git repository

query device_config($device: String!) {
  InfraDevice(name__value: $device) {
    edges {
      node {
	name {
	  value
	}
	interfaces {
	  edges {
	    node {
	      name {
		value
	      }
	    }
	  }
	}
      }
    }
  }
  InfraServer {
    edges {
      node {
	name {
	  value
	}
      }
    }
  }
}
---
jinja2_transforms:
  - name: "device_config"
    query: "device_config"
    template_path: "templates/device_config.j2"

queries:
  - name: "device_config"
    file_path: "templates/device_config.gql"

artifact_definitions:
  - name: "Device configuration"
    artifact_name: "device-configuration"
    parameters:
      device: "name__value"
    content_type: "text/plain"
    targets: "devices"
    transformation: "device_config"

Assuming we have a generated artifcat for a device in the main branch.

When you create a new branch, and add a new InfraServer node, the existing device_config artifact does not get regenerated when you open a proposed change to merge the branch into the main branch.

Expected Behavior

Since the InfraServer nodes are in the scope of the GraphQL query and therefor they affect the artifact for a given target, I would assume that the artifact gets regenerated.

Steps to Reproduce

  • create a new git repository
  • define the following .infrahub.yml file at the root of the project
---
jinja2_transforms:
  - name: "device_config"
    query: "device_config"
    template_path: "templates/device_config.j2"

queries:
  - name: "device_config"
    file_path: "templates/device_config.gql"

artifact_definitions:
  - name: "Device configuration"
    artifact_name: "device-configuration"
    parameters:
      device: "name__value"
    content_type: "text/plain"
    targets: "devices"
    transformation: "device_config"
  • create a templates directory at the root of the project
  • in the templates directory create a file device_config.gql with the following contents
query device_config($device: String!) {
  InfraDevice(name__value: $device) {
    edges {
      node {
	name {
	  value
	}
	interfaces {
	  edges {
	    node {
	      name {
		value
	      }
	    }
	  }
	}
      }
    }
  }
  InfraServer {
    edges {
      node {
	name {
	  value
	}
      }
    }
  }
}
  • create a file device_config.j2 in the templates directory with the following contents
hostname {{ data["InfraDevice"]["edges"][0]["node"]["name"]["value"] }}

{% for interface in
  data["InfraDevice"]["edges"][0]["node"]["interfaces"]["edges"] %}
interface {{ interface["node"]["name"]["value"] }}
{% endfor %}

{% for server in data["InfraServer"]["edges"] %}
server {{ server["node"]["name"]["value"] }}
{% endfor %}
  • commit changes
  • push the repository to a remote on a git server
  • spin up an instance of Infrahub
  • load the following schema
---
version: "1.0"
nodes:
  - name: Interface
    namespace: Infra
    uniqueness_constraints:
      - ["device", "name__value"]
    attributes:
      - name: name
        kind: Text
        optional: false
    relationships:
      - name: device
        peer: InfraDevice
        optional: false
        cardinality: one
        kind: Parent
  - name: Device
    namespace: Infra
    human_friendly_id:
      - "name__value"
    attributes:
      - name: name
        kind: Text
        unique: true
        optional: false
    relationships:
      - name: interfaces
        peer: InfraInterface
        cardinality: many
        optional: true
        kind: Component
  - name: Server
    namespace: Infra
    attributes:
      - name: name
        kind: Text
        optional: false
        unique: true
  • create a CoreStandardGroup devices
  • create a InfraDevice with name device
  • add the InfraDevice to the devices group
  • create an InfraInterface with name Ethernet1 and add a relationship to InfraDevice device
  • create an InfraServer with name logging
  • create the repository in Infrahub and let is sync
  • verify that you have a device_config for device
  • create a branch test
  • create a new InfrasServer named tacacs in the branch
  • open a proposed change to merge branch test into main
  • the artifact device_config for node device will not be regenerated

Additional Information

No response

@wvandeun wvandeun added type/bug Something isn't working as expected group/backend Issue related to the backend (API Server, Git Agent) labels Aug 28, 2024
@exalate-issue-sync exalate-issue-sync bot added this to the Infrahub - 0.16.1 milestone Aug 28, 2024
@exalate-issue-sync exalate-issue-sync bot added the state/planned This issue is planned to be worked on in an upcoming release. label Sep 9, 2024
@exalate-issue-sync exalate-issue-sync bot removed this from the Infrahub - 0.16.3 milestone Oct 15, 2024
@dgarros dgarros added this to the Infrahub - 1.1 milestone Oct 29, 2024
@exalate-issue-sync exalate-issue-sync bot removed the state/planned This issue is planned to be worked on in an upcoming release. label Nov 20, 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) type/bug Something isn't working as expected
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants