-
Notifications
You must be signed in to change notification settings - Fork 6
Fix infrahub/#8 #7
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
Conversation
Happy to add some unit/integration tests here if beneficial. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PhillSimonds, first of all, Thank you for your contribution!
I left some comments. If they are not clear to you, please reach out.
Thanks for the comments Wim. I've added to the comments and updated per your feedback. I also renamed the town crier doc to reflect the new issue number now that the issue has been moved to this repo. Let me know your thoughts on changing the transform run logic vs doing something else. Happy to update if there is a better way. Also, this CLI command was broken when I picked up the PR. Would you like me to add an integration test to protect this in the future? |
The client is assigned now via the cached_property.
We don't want a value passed into the function that isn't used, and likewise don't want to change the API for that init function.
The collect_data method has been updated to support acquiring data from both a stored graphql query endpoint and the standard graphql endpoint. Before, only the stored api endpoint was supported.
Wim. I updated the InfrahubTransform so that it will try to query the stored graphql query path first and query the graphql API directly in the event the stored query doesn't exist. That allows us to just call .run() on the transform class. I think that's the most elegant way to do this. Another thought here -- there seems to be some confusion in the InfrahubTransform class's understanding of "branch". It's getting the branch name from the local repo if a branch name isn't passed in, but the branch name is actually used to ask for data from the specified branch in infrahub. I believe the repo branch and infrahub branch are completely separate, so we probably shouldn't be using a repo object to look at the local branch then pass that in the API request. the |
@opsmill/backend please review this one from @PhillSimonds ! |
Hey @PhillSimonds, thank you for your contribution!
More testing overall would be great :) The CTL specifically is missing test coverage. In what way was the command currently broken? Looking through the code to initialize transforms I realize that we need to do some refactoring with regards to how it's done as we have multiple ways of doing it at present. There is a small caveat with the PR you've done with regards to how the ctl currently expects a client to be setup in the way that the config would look a bit different if we used the client returned by a call to As this currently targeting the It would be impossible to know but we're going to remove the part with I think what we need to do here is to change the initializer: class InfrahubTransform:
name: Optional[str] = None
query: str
timeout: int = 10
def __init__(self, branch: str = "", root_directory: str = "", server_url: str = "", client: Optional[InfrahubClient] = None):
self._client: InfrahubClient Then have a property for .client which currently acts as a setter/getter (later the client will be a required argument). Here the same thing could be done with Then here: try:
transform_instance = get_transform_class_instance(transform_config=transform_config)
except InfrahubTransformNotFoundError as exc:
console.print(f"Unable to load {transform_name} from python_transforms")
raise typer.Exit(1) from exc We'd add a: transform_instance.client = the-client-object A problem here with the current code could be that initialize_client is an async function even though there's no need for it to be. We should be able to change it to a sync function. Alternatively we can cheat and run initialize_client_sync and convert it: sync_client = initialize_client_sync()
async_client = InfrahubClient(config=sync_client.config) Does this make sense to you? |
Happy to contribute :).
Awesome, I'll add some tests.
Execution of the graphQL query was failing because the query wasn't loaded into the repository config object, and thus *Further calls up the stack trace omitted for brevity
The
**I filed a separate issue for the git stuff, #49. I am thinking it might make sense to create a separate PR for its full resolution, but I'm happy to integrate into this one if you think it would be better.
I think I'm following. I'll make some updates here shortly then ping for further review :) |
- Makes a synchronous function - Make .client property of InfrahubTransform a setter/getter - Add client as argument for initialization of InfrahubTransform
@ogenstad I've made the following updates:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now I'd like to remove some of the additions in this PR and focus on the main cause we're trying to solve with the bug and instead raise other issues to discuss other improvements such as the loading of queries if that is currently problematic.
Feel free to reach out if you want a quick sync around this!
infrahub_sdk/transforms.py
Outdated
if not self.repository_config: | ||
raise | ||
query_str = self.repository_config.get_query(name=self.query).load_query() | ||
return await self.client.execute_graphql(query=query_str, variables=variables, branch_name=self.branch_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to revert to the old behaviour here so that the focus of this PR is only to add the missing InfrahubClient
that was the target of #8.
While I can see that the collect_data is missing some information as it is now I'm not sure that we should add a InfrahubRepositoryConfig
object to the transform itself in order to load a missing query. I think we should handle all that in a different way. I'm curious to the root cause of this if you had problems running with a local query if it had to do with the fact that the query wasn't defined within your .infrahub.yml
file? This is my assumption based on the repository_config.queries.append(query_config_obj)
could this be correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The query was indeed not in my infrahub.yml file (hence the loading of the query in L#352-354 of cli_commands.py
, which can be removed with this in mind) -- but that isn't the root of the issue with running the transform here.
The InfrahubTransform object in stable only has access to the query name, not to the query string. The query name is able to be used in the front end because a stored query at the path f"{self.address}/api/query/{name}"
pre-exists in infrahub which returns data, so we don't actually need the query string to make the query, just the name of the query. I think this stored query path is created as part of syncing a repo (though I'm not sure). This is not the case when the infrahubctl transform
command is run, because the stored query path does not pre-exist in infrahub (unless I'm doing something wrong here). This in mind, we need the full query string to execute the query with infrahubctl transform
, not just the query name.
HTTP communication failure: Client error '403 Forbidden' for url 'http://localhost:8000/api/query/tags_query?branch=main&update_group=false'
For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/403 on POST to
http://localhost:8000/api/query/tags_query?branch=main&update_group=false
I can add a client object to the transform (as per #8), but I'll have to call the client object's .execute_graphql
method directly with the query string in order to acquire data, circumventing the transform's run method for data acquisition. I can then run the transform with that data. Is this what you're thinking would be best to resolve #8 with a more modest touch?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated per my comment there. If this isn't what you're thinking (or I'm missing something) LMK and I can modify.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates. I left a minor comment about a slight typo.
I also opened #54, which I think might have been some source of confusion for you.
Regarding the debug: #56 |
@ogenstad I've added some tests for the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the changes!
Make infrahubctl transform and render commands use InfrahubClient to communicate with GQL API.