Skip to content

Commit

Permalink
fix SchemaNotFoundError for renamed schema during diff enrichment
Browse files Browse the repository at this point in the history
  • Loading branch information
ajtmccarty authored and LucasG0 committed Dec 3, 2024
1 parent 2e01f6d commit 6e85638
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
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 @@ -4,6 +4,7 @@

from infrahub.core.manager import NodeManager
from infrahub.core.registry import registry
from infrahub.exceptions import SchemaNotFoundError
from infrahub.log import get_logger

if TYPE_CHECKING:
Expand All @@ -14,12 +15,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 @@ -31,7 +37,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
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

0 comments on commit 6e85638

Please sign in to comment.