Skip to content

Commit ad73da3

Browse files
fix: add nil check when accessing workflow nodes in retry logic
When retrying a workflow with parameter override, the code accesses wf.Status.Nodes[nodeID] without checking if the nodeID exists. Since Nodes is a map[string]NodeStatus, accessing a non-existent key returns a zero value without panicking, but it's safer to explicitly check existence using the comma-ok idiom. This prevents potential issues where toReset might contain nodeIDs that don't exist in wf.Status.Nodes in edge cases. Also renamed the second 'ok' variable to 'okNode' to avoid shadowing the first 'ok' variable. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com> Signed-off-by: Yu-Hong Shen <stanley.shen2003@gmail.com>
1 parent d191ce7 commit ad73da3

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

workflow/util/util.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,9 +1240,12 @@ func FormulateRetryWorkflow(ctx context.Context, wf *wfv1.Workflow, restartSucce
12401240
if toDelete[nodeID] {
12411241
continue
12421242
}
1243-
n := wf.Status.Nodes[nodeID]
1243+
n, ok := wf.Status.Nodes[nodeID]
1244+
if !ok {
1245+
continue
1246+
}
12441247
if n.Type == wfv1.NodeTypeTaskGroup || n.Type == wfv1.NodeTypeStepGroup {
1245-
if dagNode, ok := nodesMap[nodeID]; ok {
1248+
if dagNode, okNode := nodesMap[nodeID]; okNode {
12461249
for childID := range getChildren(dagNode) {
12471250
toDelete[childID] = true
12481251
}

0 commit comments

Comments
 (0)