Skip to content

Commit abb7771

Browse files
authored
IFC-1517 Don't set unique constraints on generic templates (#6565)
When we run the uniqueness constraint checker for a given node, we check for its uniqueness constraints as well as the uniqueness constraints of its generics if their are any. In the case of component template, it was causing an issue where component templates were expected to have unique template names while in fact, their uniqueness is based on a name and a parent template.
1 parent b11ce3a commit abb7771

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

backend/infrahub/core/schema/schema_branch.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1957,7 +1957,11 @@ def add_relationships_to_template(self, node: NodeSchema | GenericSchema) -> Non
19571957
)
19581958

19591959
parent_hfid = f"{relationship.name}__template_name__value"
1960-
if relationship.kind == RelationshipKind.PARENT and parent_hfid not in template_schema.human_friendly_id:
1960+
if (
1961+
not isinstance(template_schema, GenericSchema)
1962+
and relationship.kind == RelationshipKind.PARENT
1963+
and parent_hfid not in template_schema.human_friendly_id
1964+
):
19611965
template_schema.human_friendly_id = [parent_hfid] + template_schema.human_friendly_id
19621966
template_schema.uniqueness_constraints[0].append(relationship.name)
19631967

@@ -1992,7 +1996,6 @@ def generate_object_template_from_node(
19921996
include_in_menu=False,
19931997
display_labels=["template_name__value"],
19941998
human_friendly_id=["template_name__value"],
1995-
uniqueness_constraints=[["template_name__value"]],
19961999
attributes=[template_name_attr],
19972000
)
19982001

@@ -2011,7 +2014,6 @@ def generate_object_template_from_node(
20112014
human_friendly_id=["template_name__value"],
20122015
uniqueness_constraints=[["template_name__value"]],
20132016
inherit_from=[InfrahubKind.LINEAGESOURCE, InfrahubKind.NODE, core_template_schema.kind],
2014-
default_filter="template_name__value",
20152017
attributes=[template_name_attr],
20162018
relationships=[
20172019
RelationshipSchema(

changelog/6478.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove uniqueness constraint on generic templates to support upsert mutations

0 commit comments

Comments
 (0)