Skip to content

Commit c93784b

Browse files
authored
fix(api): workflow import link nodes to existing joins (#5069)
1 parent e1e4fc3 commit c93784b

File tree

3 files changed

+66
-5
lines changed

3 files changed

+66
-5
lines changed

sdk/exportentities/v1/workflow.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,8 +479,12 @@ func (e *NodeEntry) processNodeAncestors(name string, w *sdk.Workflow) (bool, er
479479
var join *sdk.Node
480480
for i := range w.WorkflowData.Joins {
481481
j := &w.WorkflowData.Joins[i]
482-
var joinFound = true
483482

483+
if len(e.DependsOn) != len(j.JoinContext) {
484+
continue
485+
}
486+
487+
var joinFound = true
484488
for _, ref := range j.JoinContext {
485489
var refFound bool
486490
for _, a := range e.DependsOn {

sdk/exportentities/v2/workflow.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,9 +370,9 @@ func (w Workflow) GetWorkflow() (*sdk.Workflow, error) {
370370
wf.HistoryLength = sdk.DefaultHistoryLength
371371
}
372372

373-
rand.Seed(time.Now().Unix())
373+
r := rand.New(rand.NewSource(time.Now().Unix()))
374374
var attempt int
375-
fakeID := rand.Int63n(5000)
375+
fakeID := r.Int63n(5000)
376376
// attempt is there to avoid infinite loop, but it should not happened becase we check validity and dependencies earlier
377377
for len(w.Workflow) != 0 && attempt < 10000 {
378378
for name, entry := range w.Workflow {
@@ -503,8 +503,9 @@ func (e *NodeEntry) processNodeAncestors(name string, w *sdk.Workflow) (bool, er
503503
ancestor := w.WorkflowData.NodeByName(a)
504504
if ancestor == nil {
505505
ancestorsExist = false
506+
} else {
507+
ancestors = append(ancestors, ancestor)
506508
}
507-
ancestors = append(ancestors, ancestor)
508509
} else {
509510
for _, a := range e.DependsOn {
510511
//Looking for the ancestor
@@ -546,8 +547,12 @@ func (e *NodeEntry) processNodeAncestors(name string, w *sdk.Workflow) (bool, er
546547
var join *sdk.Node
547548
for i := range w.WorkflowData.Joins {
548549
j := &w.WorkflowData.Joins[i]
549-
var joinFound = true
550550

551+
if len(e.DependsOn) != len(j.JoinContext) {
552+
continue
553+
}
554+
555+
var joinFound = true
551556
for _, ref := range j.JoinContext {
552557
var refFound bool
553558
for _, a := range e.DependsOn {

sdk/exportentities/v2/workflow_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,58 @@ workflow:
988988
- success
989989
pipeline: env
990990
one_at_a_time: true
991+
`,
992+
},
993+
{
994+
name: "Workflow no declared joins",
995+
yaml: `name: nojoins
996+
version: v2.0
997+
workflow:
998+
p1:
999+
pipeline: env
1000+
p5:
1001+
depends_on:
1002+
- p21
1003+
- p31
1004+
- p41
1005+
pipeline: env
1006+
p6:
1007+
depends_on:
1008+
- p21
1009+
- p31
1010+
- p41
1011+
- p42
1012+
pipeline: env
1013+
p7:
1014+
depends_on:
1015+
- p21
1016+
- p31
1017+
- p42
1018+
pipeline: env
1019+
p21:
1020+
depends_on:
1021+
- p1
1022+
pipeline: env
1023+
p22:
1024+
depends_on:
1025+
- p1
1026+
pipeline: env
1027+
p31:
1028+
depends_on:
1029+
- p1
1030+
pipeline: env
1031+
p32:
1032+
depends_on:
1033+
- p1
1034+
pipeline: env
1035+
p41:
1036+
depends_on:
1037+
- p1
1038+
pipeline: env
1039+
p42:
1040+
depends_on:
1041+
- p1
1042+
pipeline: env
9911043
`,
9921044
},
9931045
}

0 commit comments

Comments
 (0)