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

fix SchemaNotFoundError for renamed schema during diff enrichment #5128

Merged
merged 1 commit into from
Dec 2, 2024
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
14 changes: 11 additions & 3 deletions backend/infrahub/core/diff/payload_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from infrahub.core.constants import DiffAction, RelationshipCardinality
from infrahub.core.manager import NodeManager
from infrahub.core.registry import registry
from infrahub.exceptions import SchemaNotFoundError
from infrahub.log import get_logger

from .model.diff import (
Expand Down Expand Up @@ -42,12 +43,17 @@


async def get_display_labels_per_kind(
kind: str, ids: list[str], branch_name: str, db: InfrahubDatabase
kind: str, ids: list[str], branch_name: str, db: InfrahubDatabase, skip_missing_schema: bool = False
) -> dict[str, str]:
"""Return the display_labels of a list of nodes of a specific kind."""
branch = await registry.get_branch(branch=branch_name, db=db)
schema_branch = db.schema.get_schema_branch(name=branch.name)
fields = schema_branch.generate_fields_for_display_label(name=kind)
try:
fields = schema_branch.generate_fields_for_display_label(name=kind)
except SchemaNotFoundError:
if skip_missing_schema:
return {}
raise
nodes = await NodeManager.get_many(ids=ids, fields=fields, db=db, branch=branch)
return {node_id: await node.render_display_label(db=db) for node_id, node in nodes.items()}

Expand All @@ -59,7 +65,9 @@ async def get_display_labels(nodes: dict[str, dict[str, list[str]]], db: Infrahu
if branch_name not in response:
response[branch_name] = {}
for kind, ids in items.items():
labels = await get_display_labels_per_kind(kind=kind, ids=ids, db=db, branch_name=branch_name)
labels = await get_display_labels_per_kind(
kind=kind, ids=ids, db=db, branch_name=branch_name, skip_missing_schema=True
)
response[branch_name].update(labels)

return response
Expand Down
1 change: 1 addition & 0 deletions changelog/+schema-rename-diff.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix issue that could cause diff generation to crash if a schema was renamed
Loading