Skip to content

Finalize typing on ctl.schema #451

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

Merged
merged 1 commit into from
Jul 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions infrahub_sdk/ctl/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def validate_schema_content_and_exit(client: InfrahubClient, schemas: list[Schem
has_error: bool = False
for schema_file in schemas:
try:
client.schema.validate(data=schema_file.content)
client.schema.validate(data=schema_file.payload)
except ValidationError as exc:
console.print(f"[red]Schema not valid, found '{len(exc.errors())}' error(s) in {schema_file.location}")
has_error = True
Expand All @@ -48,7 +48,7 @@ def validate_schema_content_and_exit(client: InfrahubClient, schemas: list[Schem
raise typer.Exit(1)


def display_schema_load_errors(response: dict[str, Any], schemas_data: list[dict]) -> None:
def display_schema_load_errors(response: dict[str, Any], schemas_data: list[SchemaFile]) -> None:
console.print("[red]Unable to load the schema:")
if "detail" not in response:
handle_non_detail_errors(response=response)
Expand Down Expand Up @@ -87,7 +87,7 @@ def handle_non_detail_errors(response: dict[str, Any]) -> None:
if "error" in response:
console.print(f" {response.get('error')}")
elif "errors" in response:
for error in response.get("errors"):
for error in response["errors"]:
console.print(f" {error.get('message')}")
else:
console.print(f" '{response}'")
Expand All @@ -97,9 +97,9 @@ def valid_error_path(loc_path: list[Any]) -> bool:
return len(loc_path) >= 6 and loc_path[0] == "body" and loc_path[1] == "schemas"


def get_node(schemas_data: list[dict], schema_index: int, node_index: int) -> dict | None:
if schema_index < len(schemas_data) and node_index < len(schemas_data[schema_index].content["nodes"]):
return schemas_data[schema_index].content["nodes"][node_index]
def get_node(schemas_data: list[SchemaFile], schema_index: int, node_index: int) -> dict | None:
if schema_index < len(schemas_data) and node_index < len(schemas_data[schema_index].payload["nodes"]):
return schemas_data[schema_index].payload["nodes"][node_index]
return None


Expand All @@ -122,7 +122,7 @@ async def load(
validate_schema_content_and_exit(client=client, schemas=schemas_data)

start_time = time.time()
response = await client.schema.load(schemas=[item.content for item in schemas_data], branch=branch)
response = await client.schema.load(schemas=[item.payload for item in schemas_data], branch=branch)
loading_time = time.time() - start_time

if response.errors:
Expand Down Expand Up @@ -170,10 +170,10 @@ async def check(
client = initialize_client()
validate_schema_content_and_exit(client=client, schemas=schemas_data)

success, response = await client.schema.check(schemas=[item.content for item in schemas_data], branch=branch)
success, response = await client.schema.check(schemas=[item.payload for item in schemas_data], branch=branch)

if not success:
display_schema_load_errors(response=response, schemas_data=schemas_data)
display_schema_load_errors(response=response or {}, schemas_data=schemas_data)
else:
for schema_file in schemas_data:
console.print(f"[green] schema '{schema_file.location}' is Valid!")
Expand Down
4 changes: 0 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,6 @@ disallow_untyped_defs = true
module = "infrahub_sdk.ctl.check"
disable_error_code = ["call-overload"]

[[tool.mypy.overrides]]
module = "infrahub_sdk.ctl.schema"
disable_error_code = ["arg-type", "attr-defined", "misc", "union-attr"]

[[tool.mypy.overrides]]
module = "infrahub_sdk.utils"
disable_error_code = ["arg-type", "attr-defined", "return-value", "union-attr"]
Expand Down