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

skip profile schemas when checking for schema migrations #5446

Merged
merged 3 commits into from
Jan 14, 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
15 changes: 1 addition & 14 deletions backend/infrahub/core/validators/models/violation.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
from typing import Union

from pydantic import BaseModel, Field

from infrahub.core.branch import Branch
from infrahub.core.path import SchemaPath
from infrahub.core.schema import GenericSchema, NodeSchema


class SchemaConstraintValidatorRequest(BaseModel):
branch: Branch = Field(..., description="The name of the branch to target")
constraint_name: str = Field(..., description="The name of the constraint to validate")
node_schema: Union[NodeSchema, GenericSchema] = Field(..., description="Schema of Node or Generic to validate")
schema_path: SchemaPath = Field(..., description="SchemaPath to the element of the schema to validate")
from pydantic import BaseModel


class SchemaViolation(BaseModel):
Expand Down
5 changes: 4 additions & 1 deletion backend/infrahub/core/validators/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,14 @@ async def schema_validate_migrations(message: SchemaValidateMigrationData) -> li
log.info(f"{len(message.constraints)} constraint(s) to validate")
# NOTE this task is a good candidate to add a progress bar
for constraint in message.constraints:
schema = message.schema_branch.get(name=constraint.path.schema_kind)
if not isinstance(schema, (GenericSchema, NodeSchema)):
continue
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A thought could be to reverse this by saying that what we want to have is a GenericSchema or a NodeSchema. I'm mostly thinking about a future scenario if we introduce some other type of schema SomethingElseSchema (I have no idea of what that might be). If we were to do that this function might be invalid again as it would catch entries that we might not want.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great suggestion. I've made this change

batch.add(
task=schema_path_validate,
branch=message.branch,
constraint_name=constraint.constraint_name,
node_schema=message.schema_branch.get(name=constraint.path.schema_kind),
node_schema=schema,
schema_path=constraint.path,
)

Expand Down
Loading