Skip to content

Commit 6f9ff2a

Browse files
authored
Merge pull request #7439 from opsmill/pog-fix-hfid-setup
Fix order for registering HFID
2 parents c38c822 + 4beb75e commit 6f9ff2a

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
@@ -574,6 +574,7 @@ def process_post_validation(self) -> None:
574574
self.process_dropdowns()
575575
self.process_relationships()
576576
self.process_human_friendly_id()
577+
self.register_human_friendly_id()
577578

578579
def _generate_identifier_string(self, node_kind: str, peer_kind: str) -> str:
579580
return "__".join(sorted([node_kind, peer_kind])).lower()
@@ -909,7 +910,6 @@ def _is_attr_combination_unique(
909910
return False
910911

911912
def validate_human_friendly_id(self) -> None:
912-
self.hfids = HFIDs()
913913
for name in self.generic_names_without_templates + self.node_names:
914914
node_schema = self.get(name=name, duplicate=False)
915915

@@ -943,11 +943,6 @@ def validate_human_friendly_id(self) -> None:
943943
rel_schemas_to_paths[rel_identifier] = (schema_path.related_schema, [])
944944
rel_schemas_to_paths[rel_identifier][1].append(schema_path.attribute_path_as_str)
945945

946-
if node_schema.is_node_schema and node_schema.namespace not in ["Schema", "Internal"]:
947-
self.hfids.register_hfid_schema_path(
948-
kind=node_schema.kind, schema_path=schema_path, hfid=node_schema.human_friendly_id
949-
)
950-
951946
if config.SETTINGS.main.schema_strict_mode:
952947
# For every relationship referred within hfid, check whether the combination of attributes is unique is the peer schema node
953948
for related_schema, attrs_paths in rel_schemas_to_paths.values():
@@ -1549,6 +1544,34 @@ def process_human_friendly_id(self) -> None:
15491544
node.uniqueness_constraints = [hfid_uniqueness_constraint]
15501545
self.set(name=node.kind, schema=node)
15511546

1547+
def register_human_friendly_id(self) -> None:
1548+
"""Register HFID automations
1549+
1550+
Register the HFIDs after all processing and validation has been done.
1551+
"""
1552+
1553+
self.hfids = HFIDs()
1554+
for name in self.generic_names_without_templates + self.node_names:
1555+
node_schema = self.get(name=name, duplicate=False)
1556+
1557+
if not node_schema.human_friendly_id:
1558+
continue
1559+
1560+
allowed_types = SchemaElementPathType.ATTR_WITH_PROP | SchemaElementPathType.REL_ONE_MANDATORY_ATTR
1561+
1562+
for hfid_path in node_schema.human_friendly_id:
1563+
schema_path = self.validate_schema_path(
1564+
node_schema=node_schema,
1565+
path=hfid_path,
1566+
allowed_path_types=allowed_types,
1567+
element_name="human_friendly_id",
1568+
)
1569+
1570+
if node_schema.is_node_schema and node_schema.namespace not in ["Schema", "Internal"]:
1571+
self.hfids.register_hfid_schema_path(
1572+
kind=node_schema.kind, schema_path=schema_path, hfid=node_schema.human_friendly_id
1573+
)
1574+
15521575
def process_hierarchy(self) -> None:
15531576
for name in self.nodes.keys():
15541577
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)