Skip to content

Commit b421471

Browse files
committed
Refactor GraphTemplate model for improved parent tracking and error handling
- Updated the _parents_by_identifier attribute to use a set for better performance in parent relationship management. - Simplified the error checking logic for dependencies, ensuring clarity and correctness in identifying parent-child relationships. These changes enhance the accuracy and efficiency of the GraphTemplate model's dependency management.
1 parent 9c04c73 commit b421471

1 file changed

Lines changed: 4 additions & 9 deletions

File tree

state-manager/app/models/db/graph_template_model.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,13 @@ def _build_parents_by_identifier(self) -> None:
6464
visited = {node.identifier: False for node in self.nodes}
6565
awaiting_parent: dict[str, list[str]] = {}
6666

67-
self._parents_by_identifier = {}
67+
self._parents_by_identifier: dict[str, set[str]] = {}
68+
6869
for node in self.nodes:
6970
self._parents_by_identifier[node.identifier] = set()
7071
visited[node.identifier] = False
7172

7273
def dfs(node_identifier: str, parents: set[str]) -> None:
73-
assert self._parents_by_identifier is not None
74-
7574
self._parents_by_identifier[node_identifier] = parents | self._parents_by_identifier[node_identifier]
7675

7776
if visited[node_identifier]:
@@ -242,12 +241,8 @@ def verify_input_dependencies(self) -> Self:
242241
dependent_identifiers = set([identifier for identifier, _ in dependent_string.get_identifier_field()])
243242

244243
for identifier in dependent_identifiers:
245-
if node.unites is not None:
246-
if identifier not in self.get_parents_by_identifier(node.unites.identifier):
247-
errors.append(f"Input {input_value} depends on {identifier} but {identifier} is not a parent of unites {node.unites.identifier}")
248-
else:
249-
if identifier not in self.get_parents_by_identifier(node.identifier):
250-
errors.append(f"Input {input_value} depends on {identifier} but {identifier} is not a parent of {node.identifier}")
244+
if identifier not in self.get_parents_by_identifier(node.identifier):
245+
errors.append(f"Input {input_value} depends on {identifier} but {identifier} is not a parent of {node.identifier}")
251246

252247
except Exception as e:
253248
errors.append(f"Error creating dependent string for input {input_value}: {e}")

0 commit comments

Comments
 (0)