Skip to content

Commit

Permalink
Merge pull request #14 from capitec/feature/catch-error-recursive-tree
Browse files Browse the repository at this point in the history
Fix error catching for recursive tree
  • Loading branch information
sjnarmstrong authored Jan 14, 2025
2 parents 2d352fe + 79b33cf commit 0bc66cf
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions spockflow/components/tree/v1/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,15 @@ def _identify_loops(self, *nodes: "ConditionedNode"):
def _remove_nodes_from_end(*nodes: "ConditionedNode", child_tree: ChildTree):
# Not the most pythonic method can maybe be improved
# Done to remove elements in the order they were added
nodes_to_remove = list(nodes)
nodes_to_remove = set(map(id, list(nodes)))
last_el_idx = len(child_tree.nodes) - 1
for rev_i, node in enumerate(reversed(child_tree.nodes)):
i = last_el_idx - rev_i
if node in nodes_to_remove:
if id(node) in nodes_to_remove:
child_tree.nodes.pop(i)
if len(nodes_to_remove) <= 0:
return True
nodes_to_remove.discard(id(node))
if len(nodes_to_remove) <= 0:
return True
return False

def copy(self, deep=True):
Expand Down

0 comments on commit 0bc66cf

Please sign in to comment.