Skip to content

Commit 02a166e

Browse files
committed
Change var name
1 parent c952942 commit 02a166e

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

backend/infrahub/core/schema/schema_branch.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2143,28 +2143,33 @@ def add_groups(self) -> None:
21432143

21442144
# On auto-generated templates, also expose template-side fields whose peers drive instance group membership at template application time
21452145
if isinstance(schema, TemplateSchema):
2146-
schema, changed = self._add_template_group_for_instances_relationships(schema=schema, changed=changed)
2146+
schema, changed = self._add_template_group_for_instances_relationships(
2147+
schema=schema, schema_duplicated=changed
2148+
)
21472149

21482150
if changed:
21492151
self.set(name=node_name, schema=schema)
21502152

21512153
def _add_template_group_for_instances_relationships(
2152-
self, schema: MainSchemaTypes, changed: bool
2154+
self, schema: MainSchemaTypes, schema_duplicated: bool
21532155
) -> tuple[MainSchemaTypes, bool]:
21542156
"""Append `member_of_groups_for_instances` / `subscriber_of_groups_for_instances` on a template.
21552157
2156-
These are generic relationships using distinct identifiers so adding peers does not put the template node into
2157-
a group.
2158+
These are generic relationships using distinct identifiers so adding peers does not put the template object
2159+
into a group.
2160+
2161+
`schema_duplicated` reflects whether the caller has already duplicated `schema`. The helper duplicates on
2162+
first mutation if needed and returns the updated state so the caller knows whether anything was changed.
21582163
"""
21592164
for rel_name, identifier in (
21602165
("member_of_groups_for_instances", "template_group_member_for_instances"),
21612166
("subscriber_of_groups_for_instances", "template_group_subscriber_for_instances"),
21622167
):
21632168
if rel_name in schema.relationship_names:
21642169
continue
2165-
if not changed:
2170+
if not schema_duplicated:
21662171
schema = schema.duplicate()
2167-
changed = True
2172+
schema_duplicated = True
21682173
schema.relationships.append(
21692174
RelationshipSchema(
21702175
name=rel_name,
@@ -2176,7 +2181,7 @@ def _add_template_group_for_instances_relationships(
21762181
branch=BranchSupportType.AWARE,
21772182
)
21782183
)
2179-
return schema, changed
2184+
return schema, schema_duplicated
21802185

21812186
def _get_hierarchy_child_rel(self, peer: str, hierarchical: str | None, read_only: bool) -> RelationshipSchema:
21822187
return RelationshipSchema(

0 commit comments

Comments
 (0)