Skip to content

Commit 26a2460

Browse files
sguiheuxyesnault
authored andcommitted
fix(api): insert node that already exist (#3617)
1 parent 0da717b commit 26a2460

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

engine/api/workflow/dao_data_trigger.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ func insertNodeTriggerData(db gorp.SqlExecutor, w *sdk.Workflow, n *sdk.Node) er
1414
for i := range n.Triggers {
1515
t := &n.Triggers[i]
1616
t.ID = 0
17-
// Create child to get its ID
18-
if err := insertNodeData(db, w, &t.ChildNode, false); err != nil {
19-
return sdk.WrapError(err, "insertNodeTriggerData> Unable to insert destination node")
20-
}
2117

22-
// Set ID
18+
// Is child already exist
19+
if t.ChildNode.ID == 0 {
20+
// Create child to get its ID
21+
if err := insertNodeData(db, w, &t.ChildNode, false); err != nil {
22+
return sdk.WrapError(err, "Unable to insert destination node")
23+
}
24+
}
2325
t.ChildNodeID = t.ChildNode.ID
2426
t.ParentNodeID = n.ID
2527

engine/api/workflow/dao_test.go

+4-7
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,6 @@ func TestUpdateSimpleWorkflowWithApplicationEnvPipelineParametersAndPayload(t *t
575575
WorkflowData: &sdk.WorkflowData{
576576
Node: sdk.Node{
577577
Name: "node1",
578-
Ref: "node1",
579578
Type: sdk.NodeTypePipeline,
580579
Context: &sdk.NodeContext{
581580
PipelineID: pip.ID,
@@ -600,7 +599,6 @@ func TestUpdateSimpleWorkflowWithApplicationEnvPipelineParametersAndPayload(t *t
600599
{
601600
ChildNode: sdk.Node{
602601
Name: "node2",
603-
Ref: "node2",
604602
Context: &sdk.NodeContext{
605603
PipelineID: pip3.ID,
606604
},
@@ -623,9 +621,8 @@ func TestUpdateSimpleWorkflowWithApplicationEnvPipelineParametersAndPayload(t *t
623621
t.Logf("Modifying workflow... with %d instead of %d", app2.ID, app.ID)
624622

625623
w1.Name = "test_2"
626-
w1.Root.PipelineID = pip2.ID
627-
w1.Root.Context.Application = &app2
628-
w1.Root.Context.ApplicationID = app2.ID
624+
w1.WorkflowData.Node.Context.PipelineID = pip2.ID
625+
w1.WorkflowData.Node.Context.ApplicationID = app2.ID
629626

630627
test.NoError(t, workflow.Update(context.TODO(), db, cache, w1, w1old, proj, u))
631628

@@ -634,8 +631,8 @@ func TestUpdateSimpleWorkflowWithApplicationEnvPipelineParametersAndPayload(t *t
634631
test.NoError(t, err)
635632

636633
assert.Equal(t, w1.ID, w2.ID)
637-
assert.Equal(t, app2.ID, w2.Root.Context.Application.ID)
638-
assert.Equal(t, env.ID, w2.Root.Context.Environment.ID)
634+
assert.Equal(t, app2.ID, w2.WorkflowData.Node.Context.ApplicationID)
635+
assert.Equal(t, env.ID, w2.WorkflowData.Node.Context.EnvironmentID)
639636

640637
test.NoError(t, workflow.Delete(context.TODO(), db, cache, proj, w2))
641638
}

sdk/workflow.go

+4
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ func (w *Workflow) ResetIDs() {
165165
(&t.WorkflowDestNode).ResetIDs()
166166
}
167167
}
168+
169+
for _, n := range w.WorkflowData.Array() {
170+
n.ID = 0
171+
}
168172
}
169173

170174
//Nodes returns nodes IDs excluding the root ID

0 commit comments

Comments
 (0)