Skip to content

Commit 6cc1c24

Browse files
committed
Fix issue with menu load due to missing direction
1 parent 3bf1c5c commit 6cc1c24

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

changelog/+3bf1c5c.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix an issue with with `infrahubctl menu load` that would fail while loading the menu

infrahub_sdk/schema.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,12 @@ class RelationshipCardinality(str, Enum):
282282
MANY = "many"
283283

284284

285+
class RelationshipDirection(str, Enum):
286+
BIDIR = "bidirectional"
287+
OUTBOUND = "outbound"
288+
INBOUND = "inbound"
289+
290+
285291
class BranchSupportType(str, Enum):
286292
AWARE = "aware"
287293
AGNOSTIC = "agnostic"
@@ -339,6 +345,7 @@ class RelationshipSchema(BaseModel):
339345
state: SchemaState = SchemaState.PRESENT
340346
name: str
341347
peer: str
348+
direction: RelationshipDirection = RelationshipDirection.BIDIR
342349
kind: RelationshipKind = RelationshipKind.GENERIC
343350
label: Optional[str] = None
344351
description: Optional[str] = None
@@ -413,6 +420,21 @@ def get_relationship_by_identifier(self, id: str, raise_on_error: bool = True) -
413420

414421
raise ValueError(f"Unable to find the relationship {id}")
415422

423+
def get_matching_relationship(
424+
self, id: str, direction: RelationshipDirection = RelationshipDirection.BIDIR
425+
) -> RelationshipSchema:
426+
valid_direction = RelationshipDirection.BIDIR
427+
if direction == RelationshipDirection.INBOUND:
428+
valid_direction = RelationshipDirection.OUTBOUND
429+
elif direction == RelationshipDirection.OUTBOUND:
430+
valid_direction = RelationshipDirection.INBOUND
431+
432+
for item in self.relationships:
433+
if item.identifier == id and item.direction == valid_direction:
434+
return item
435+
436+
raise ValueError(f"Unable to find the relationship {id} / ({valid_direction.value})")
437+
416438
@property
417439
def attribute_names(self) -> list[str]:
418440
return [item.name for item in self.attributes]

infrahub_sdk/spec/object.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ async def create_node(
7878
if rel_schema.identifier is None:
7979
raise ValueError("identifier must be defined")
8080

81-
peer_rel = peer_schema.get_relationship_by_identifier(id=rel_schema.identifier)
81+
peer_rel = peer_schema.get_matching_relationship(id=rel_schema.identifier, direction=rel_schema.direction)
8282

8383
rel_data = data[rel]["data"]
8484
context = {}

0 commit comments

Comments
 (0)