Skip to content

Commit 4beb75e

Browse files
committed
Fix order for registering HFID
1 parent 96731c0 commit 4beb75e

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

backend/infrahub/core/schema/schema_branch.py

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,7 @@ def process_post_validation(self) -> None:
557557
self.process_dropdowns()
558558
self.process_relationships()
559559
self.process_human_friendly_id()
560+
self.register_human_friendly_id()
560561

561562
def _generate_identifier_string(self, node_kind: str, peer_kind: str) -> str:
562563
return "__".join(sorted([node_kind, peer_kind])).lower()
@@ -892,7 +893,6 @@ def _is_attr_combination_unique(
892893
return False
893894

894895
def validate_human_friendly_id(self) -> None:
895-
self.hfids = HFIDs()
896896
for name in self.generic_names_without_templates + self.node_names:
897897
node_schema = self.get(name=name, duplicate=False)
898898

@@ -926,11 +926,6 @@ def validate_human_friendly_id(self) -> None:
926926
rel_schemas_to_paths[rel_identifier] = (schema_path.related_schema, [])
927927
rel_schemas_to_paths[rel_identifier][1].append(schema_path.attribute_path_as_str)
928928

929-
if node_schema.is_node_schema and node_schema.namespace not in ["Schema", "Internal"]:
930-
self.hfids.register_hfid_schema_path(
931-
kind=node_schema.kind, schema_path=schema_path, hfid=node_schema.human_friendly_id
932-
)
933-
934929
if config.SETTINGS.main.schema_strict_mode:
935930
# For every relationship referred within hfid, check whether the combination of attributes is unique is the peer schema node
936931
for related_schema, attrs_paths in rel_schemas_to_paths.values():
@@ -1532,6 +1527,34 @@ def process_human_friendly_id(self) -> None:
15321527
node.uniqueness_constraints = [hfid_uniqueness_constraint]
15331528
self.set(name=node.kind, schema=node)
15341529

1530+
def register_human_friendly_id(self) -> None:
1531+
"""Register HFID automations
1532+
1533+
Register the HFIDs after all processing and validation has been done.
1534+
"""
1535+
1536+
self.hfids = HFIDs()
1537+
for name in self.generic_names_without_templates + self.node_names:
1538+
node_schema = self.get(name=name, duplicate=False)
1539+
1540+
if not node_schema.human_friendly_id:
1541+
continue
1542+
1543+
allowed_types = SchemaElementPathType.ATTR_WITH_PROP | SchemaElementPathType.REL_ONE_MANDATORY_ATTR
1544+
1545+
for hfid_path in node_schema.human_friendly_id:
1546+
schema_path = self.validate_schema_path(
1547+
node_schema=node_schema,
1548+
path=hfid_path,
1549+
allowed_path_types=allowed_types,
1550+
element_name="human_friendly_id",
1551+
)
1552+
1553+
if node_schema.is_node_schema and node_schema.namespace not in ["Schema", "Internal"]:
1554+
self.hfids.register_hfid_schema_path(
1555+
kind=node_schema.kind, schema_path=schema_path, hfid=node_schema.human_friendly_id
1556+
)
1557+
15351558
def process_hierarchy(self) -> None:
15361559
for name in self.nodes.keys():
15371560
node = self.get_node(name=name, duplicate=False)

backend/infrahub/display_labels/tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ async def display_labels_setup_jinja2(
152152

153153
@flow(
154154
name="trigger-update-display-labels",
155-
flow_run_name="Trigger updates for display labels for kind",
155+
flow_run_name="Trigger updates for display labels for {kind}",
156156
)
157157
async def trigger_update_display_labels(
158158
branch_name: str,

backend/infrahub/hfid/tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ async def hfid_setup(context: InfrahubContext, branch_name: str | None = None, e
151151

152152
@flow(
153153
name="trigger-update-hfid",
154-
flow_run_name="Trigger updates for display labels for kind",
154+
flow_run_name="Trigger updates for HFID for {kind}",
155155
)
156156
async def trigger_update_hfid(
157157
branch_name: str,

0 commit comments

Comments
 (0)