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: Infrahubctl protocols command requires explicit branch #104

Open
BaptisteGi opened this issue Oct 23, 2024 · 1 comment
Open

bug: Infrahubctl protocols command requires explicit branch #104

BaptisteGi opened this issue Oct 23, 2024 · 1 comment
Assignees
Labels
type/bug Something isn't working as expected

Comments

@BaptisteGi
Copy link
Contributor

Component

infrahubctl

Infrahub SDK version

0.14.1

Current Behavior

> infrahubctl protocols
HTTP communication failure: Client error '400 Bad Request' for url 'http://localhost:8000/api/schema?branch=None'
For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/400 on GET to http://localhost:8000/api/schema?branch=None

Expected Behavior

I would expect the command to get the default branch from my environment.

The same way I could do infrahubctl schema load schema.yml without having to specify the branch

Steps to Reproduce

Doesn't work:

infrahubctl protocols

Works:

infrahubctl protocols --branch main

Additional Information

No response

@BaptisteGi BaptisteGi added the type/bug Something isn't working as expected label Oct 23, 2024
@BaptisteGi BaptisteGi self-assigned this Oct 23, 2024
@ogenstad
Copy link
Contributor

Looking at this I'd argue that it's also incorrect for infrahubctl schema load schema.yml with regards to the branch being hardcoded to main. Something like this would be more correct. We can perhaps add it for the protocols for now and then review the other commands for the next release.

diff --git a/infrahub_sdk/ctl/cli_commands.py b/infrahub_sdk/ctl/cli_commands.py
index fde4b16..3e4059b 100644
--- a/infrahub_sdk/ctl/cli_commands.py
+++ b/infrahub_sdk/ctl/cli_commands.py
@@ -366,9 +366,9 @@ def transform(

 @app.command(name="protocols")
 @catch_exception(console=console)
-def protocols(  # noqa: PLR0915
+def protocols(
     schemas: list[Path] = typer.Option(None, help="List of schemas or directory to load."),
-    branch: str = typer.Option(None, help="Branch of schema to export Python protocols for."),
+    branch: Optional[str] = typer.Option(None, help="Branch of schema to export Python protocols for."),
     sync: bool = typer.Option(False, help="Generate for sync or async."),
     _: str = CONFIG_PARAM,
     out: str = typer.Option("schema_protocols.py", help="Path to a file to save the result."),
@@ -388,6 +388,7 @@ def protocols(  # noqa: PLR0915

     else:
         client = initialize_client_sync()
+        branch = branch or client.default_branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Something isn't working as expected
Projects
None yet
Development

No branches or pull requests

2 participants