Skip to content

Commit 09e3dea

Browse files
committed
fix(backend): lesser schema duplicate
Signed-off-by: Fatih Acar <[email protected]>
1 parent f225205 commit 09e3dea

File tree

6 files changed

+20
-13
lines changed

6 files changed

+20
-13
lines changed

backend/infrahub/core/manager.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,15 @@ def identify_node_class(node: NodeToProcess) -> type[Node]:
6363

6464

6565
def get_schema(
66-
db: InfrahubDatabase, branch: Branch, node_schema: type[SchemaProtocol] | MainSchemaTypes | str
66+
db: InfrahubDatabase,
67+
branch: Branch,
68+
node_schema: type[SchemaProtocol] | MainSchemaTypes | str,
69+
duplicate: bool = False,
6770
) -> MainSchemaTypes:
6871
if isinstance(node_schema, str):
69-
return db.schema.get(name=node_schema, branch=branch.name)
72+
return db.schema.get(name=node_schema, branch=branch.name, duplicate=duplicate)
7073
if hasattr(node_schema, "_is_runtime_protocol") and node_schema._is_runtime_protocol:
71-
return db.schema.get(name=node_schema.__name__, branch=branch.name)
74+
return db.schema.get(name=node_schema.__name__, branch=branch.name, duplicate=duplicate)
7275
if not isinstance(node_schema, (MainSchemaTypes)):
7376
raise ValueError(f"Invalid schema provided {node_schema}")
7477

backend/infrahub/core/node/constraints/attribute_uniqueness.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ async def check(self, node: Node, at: Timestamp | None = None, filters: list[str
2929
attr = getattr(node, unique_attr.name)
3030
if unique_attr.inherited:
3131
for generic_parent_schema_name in node_schema.inherit_from:
32-
generic_parent_schema = self.db.schema.get(generic_parent_schema_name, branch=self.branch)
32+
generic_parent_schema = self.db.schema.get(
33+
generic_parent_schema_name, branch=self.branch, duplicate=False
34+
)
3335
parent_attr = generic_parent_schema.get_attribute_or_none(unique_attr.name)
3436
if parent_attr is None:
3537
continue

backend/infrahub/core/relationship/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ async def resolve(self, db: InfrahubDatabase, at: Timestamp | None = None) -> No
440440
self.set_peer(value=peer)
441441

442442
if not self.peer_id and self.peer_hfid:
443-
peer_schema = db.schema.get(name=self.schema.peer, branch=self.branch)
443+
peer_schema = db.schema.get(name=self.schema.peer, branch=self.branch, duplicate=False)
444444
kind = (
445445
self.data["kind"]
446446
if isinstance(self.data, dict) and "kind" in self.data and peer_schema.is_generic_schema

backend/infrahub/core/schema/node_schema.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,12 @@ def inherit_from_interface(self, interface: GenericSchema) -> None:
129129
item_idx = existing_inherited_relationships[relationship.name]
130130
self.relationships[item_idx].update_from_generic(other=new_relationship)
131131

132-
def get_hierarchy_schema(self, db: InfrahubDatabase, branch: Branch | str | None = None) -> GenericSchema:
132+
def get_hierarchy_schema(
133+
self, db: InfrahubDatabase, branch: Branch | str | None = None, duplicate: bool = False
134+
) -> GenericSchema:
133135
if not self.hierarchy:
134136
raise ValueError("The node is not part of a hierarchy")
135-
schema = db.schema.get(name=self.hierarchy, branch=branch)
137+
schema = db.schema.get(name=self.hierarchy, branch=branch, duplicate=duplicate)
136138
if not isinstance(schema, GenericSchema):
137139
raise TypeError
138140
return schema

backend/infrahub/core/validators/relationship/peer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class RelationshipPeerUpdateValidatorQuery(RelationshipSchemaValidatorQuery):
2222
name = "relationship_constraints_peer_validator"
2323

2424
async def query_init(self, db: InfrahubDatabase, **kwargs: dict[str, Any]) -> None: # noqa: ARG002
25-
peer_schema = db.schema.get(name=self.relationship_schema.peer, branch=self.branch)
25+
peer_schema = db.schema.get(name=self.relationship_schema.peer, branch=self.branch, duplicate=False)
2626
allowed_peer_kinds = [peer_schema.kind]
2727
if isinstance(peer_schema, GenericSchema):
2828
allowed_peer_kinds += peer_schema.used_by

backend/infrahub/graphql/mutations/schema.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ async def mutate(
8181
_validate_schema_permission(graphql_context=graphql_context)
8282
await apply_external_context(graphql_context=graphql_context, context_input=context)
8383

84-
kind = graphql_context.db.schema.get(name=str(data.kind), branch=graphql_context.branch.name)
84+
kind = graphql_context.db.schema.get(name=str(data.kind), branch=graphql_context.branch.name, duplicate=False)
8585
attribute = str(data.attribute)
8686
validate_kind_dropdown(kind=kind, attribute=attribute)
8787
dropdown = str(data.dropdown)
@@ -104,7 +104,7 @@ async def mutate(
104104
context=graphql_context.get_context(),
105105
)
106106

107-
kind = graphql_context.db.schema.get(name=str(data.kind), branch=graphql_context.branch.name)
107+
kind = graphql_context.db.schema.get(name=str(data.kind), branch=graphql_context.branch.name, duplicate=False)
108108
attrib = kind.get_attribute(attribute)
109109
dropdown_entry = {}
110110
success = False
@@ -141,7 +141,7 @@ async def mutate(
141141
graphql_context: GraphqlContext = info.context
142142

143143
_validate_schema_permission(graphql_context=graphql_context)
144-
kind = graphql_context.db.schema.get(name=str(data.kind), branch=graphql_context.branch.name)
144+
kind = graphql_context.db.schema.get(name=str(data.kind), branch=graphql_context.branch.name, duplicate=False)
145145
await apply_external_context(graphql_context=graphql_context, context_input=context)
146146

147147
attribute = str(data.attribute)
@@ -197,7 +197,7 @@ async def mutate(
197197
graphql_context: GraphqlContext = info.context
198198

199199
_validate_schema_permission(graphql_context=graphql_context)
200-
kind = graphql_context.db.schema.get(name=str(data.kind), branch=graphql_context.branch.name)
200+
kind = graphql_context.db.schema.get(name=str(data.kind), branch=graphql_context.branch.name, duplicate=False)
201201
await apply_external_context(graphql_context=graphql_context, context_input=context)
202202

203203
attribute = str(data.attribute)
@@ -243,7 +243,7 @@ async def mutate(
243243
graphql_context: GraphqlContext = info.context
244244

245245
_validate_schema_permission(graphql_context=graphql_context)
246-
kind = graphql_context.db.schema.get(name=str(data.kind), branch=graphql_context.branch.name)
246+
kind = graphql_context.db.schema.get(name=str(data.kind), branch=graphql_context.branch.name, duplicate=False)
247247
await apply_external_context(graphql_context=graphql_context, context_input=context)
248248

249249
attribute = str(data.attribute)

0 commit comments

Comments
 (0)