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: importing functions from other modules in repository doens't work consistently #81

Open
wvandeun opened this issue Oct 15, 2024 · 0 comments
Labels
priority/2 This issue stalls work on the project or its dependents, it's a blocker for a release type/bug Something isn't working as expected

Comments

@wvandeun
Copy link
Contributor

wvandeun commented Oct 15, 2024

Component

Python SDK, infrahubctl

Infrahub SDK version

0.14.0

Current Behavior

When you want to import functions (or classes, variables) from other python modules into python transformations or generators then there is inconsistency on how this can be achieved.

resource infrahubctl (relative) infrahubctl (absolute) Infrahub (relative) Infrahub (absolute)
transform
generator

Expected Behavior

Ideally we can import functions / classes variables from modules using relative imports when doing this in tranformations and generators, running locally or within Infrahub.

This way common code in transformations and generators can be shared in modules that are located anywhere within the repository.

Steps to Reproduce

  • load an instance of Infrahub with the demo schema
  • create a BuiltinTag node
  • create an external repository
  • define the following .infrahub.yml file
---
queries:
  - name: test
    file_path: test.gql

python_transforms:
  - name: configuration
    file_path: transformers/configuration.py
    class_name: Configuration
  • create a directory transformers in the root of the repository
  • create a file transformers/configurations.py with the following contents
from typing import Any, Dict
from infrahub_sdk.transforms import InfrahubTransform

from .utils import get_value

class Configuration(InfrahubTransform):
    query: str = "test"

    async def transform(self, data: Dict[str, Any]) -> Dict[str, Any]:
        return {
            "utils.get_value": get_value(),
        }
  • create a file transformers/utils.py with the following contents
def get_value() -> str:
    return "value"
  • create a file test.gql at the root of the repository with the following contents
query test($name: String!) {
  BuiltinTag(name__value: $name) {
    edges {
      node {
	name {
	  value
	}
      }
    }
  }
}
  • stage all the newly created files and commit them
  • try running the transformation using infrahubctl transform configuration > issue importing the get_value function
  • push the changes to a git remote
  • import the repository into Infrahub
  • run the transformation through the REST API > works

Additional Information

No response

@wvandeun wvandeun added the type/bug Something isn't working as expected label Oct 15, 2024
@exalate-issue-sync exalate-issue-sync bot added the priority/2 This issue stalls work on the project or its dependents, it's a blocker for a release label Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority/2 This issue stalls work on the project or its dependents, it's a blocker for a release type/bug Something isn't working as expected
Projects
None yet
Development

No branches or pull requests

1 participant