Skip to content

Commit 23019b5

Browse files
hjothamendixclaude
andcommitted
fix: honor UseReturnVariable when emitting call-action assignments
formatAction emitted `$Var = call microflow/nanoflow/java/javascript/external` whenever the action's ResultVariableName/OutputVariableName was non-empty, ignoring UseReturnVariable. Studio Pro stores the variable name as a UI fallback even when UseReturnVariable=false (the action discards its return), so re-exec of described MDL introduced phantom output variable declarations. Symptom: microflows with two call actions pointing at the same sub-microflow/Java action, both with UseReturnVariable=false but both carrying the same ResultVariableName, round-tripped as two declarations of the same output variable, triggering CE0111 "Duplicate variable name" in Studio Pro. Fix: emit the `$Var = ` prefix only when UseReturnVariable is true. Applies to MicroflowCallAction, NanoflowCallAction, JavaActionCallAction, JavaScriptActionCallAction, and CallExternalAction. Existing tests that relied on the old behavior now set UseReturnVariable explicitly — they were exercising the wrong BSON shape. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 1145f6b commit 23019b5

3 files changed

Lines changed: 16 additions & 6 deletions

File tree

mdl/executor/cmd_javaactions_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ func TestFormatAction_JavaActionCall_EntityTypeParam(t *testing.T) {
1919
action := &microflows.JavaActionCallAction{
2020
JavaAction: "MyModule.Validate",
2121
ResultVariableName: "IsValid",
22+
UseReturnVariable: true,
2223
ParameterMappings: []*microflows.JavaActionParameterMapping{
2324
{
2425
Parameter: "MyModule.Validate.InputObject",
@@ -40,6 +41,7 @@ func TestFormatAction_JavaActionCall_MixedParamTypes(t *testing.T) {
4041
action := &microflows.JavaActionCallAction{
4142
JavaAction: "MyModule.ProcessEntity",
4243
ResultVariableName: "Result",
44+
UseReturnVariable: true,
4345
ParameterMappings: []*microflows.JavaActionParameterMapping{
4446
{
4547
Parameter: "MyModule.ProcessEntity.InputObject",
@@ -67,6 +69,7 @@ func TestFormatAction_JavaActionCall_EntityTypeParam_EmptyEntity(t *testing.T) {
6769
action := &microflows.JavaActionCallAction{
6870
JavaAction: "MyModule.Validate",
6971
ResultVariableName: "IsValid",
72+
UseReturnVariable: true,
7073
ParameterMappings: []*microflows.JavaActionParameterMapping{
7174
{
7275
Parameter: "MyModule.Validate.InputObject",
@@ -280,6 +283,7 @@ func TestFormatAction_JavaActionCall_EntityTypeAndParameterizedParams(t *testing
280283
action := &microflows.JavaActionCallAction{
281284
JavaAction: "MyModule.CopyAttributes",
282285
ResultVariableName: "Result",
286+
UseReturnVariable: true,
283287
ParameterMappings: []*microflows.JavaActionParameterMapping{
284288
{
285289
Parameter: "MyModule.CopyAttributes.EntityType",

mdl/executor/cmd_microflows_format_action.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ func formatAction(
484484
paramStr = strings.Join(params, ", ")
485485
}
486486

487-
if a.ResultVariableName != "" {
487+
if a.UseReturnVariable && a.ResultVariableName != "" {
488488
return fmt.Sprintf("$%s = call microflow %s(%s);", a.ResultVariableName, mfName, paramStr)
489489
}
490490
return fmt.Sprintf("call microflow %s(%s);", mfName, paramStr)
@@ -513,7 +513,7 @@ func formatAction(
513513
paramStr = strings.Join(params, ", ")
514514
}
515515

516-
if a.OutputVariableName != "" {
516+
if a.UseReturnVariable && a.OutputVariableName != "" {
517517
return fmt.Sprintf("$%s = call nanoflow %s(%s);", a.OutputVariableName, nfName, paramStr)
518518
}
519519
return fmt.Sprintf("call nanoflow %s(%s);", nfName, paramStr)
@@ -557,7 +557,7 @@ func formatAction(
557557
paramStr = strings.Join(params, ", ")
558558
}
559559

560-
if a.ResultVariableName != "" {
560+
if a.UseReturnVariable && a.ResultVariableName != "" {
561561
return fmt.Sprintf("$%s = call java action %s(%s);", a.ResultVariableName, javaActionName, paramStr)
562562
}
563563
return fmt.Sprintf("call java action %s(%s);", javaActionName, paramStr)
@@ -582,7 +582,7 @@ func formatAction(
582582
paramStr = strings.Join(params, ", ")
583583
}
584584

585-
if a.ResultVariableName != "" {
585+
if a.UseReturnVariable && a.ResultVariableName != "" {
586586
return fmt.Sprintf("$%s = call external action %s.%s(%s);", a.ResultVariableName, serviceName, actionName, paramStr)
587587
}
588588
return fmt.Sprintf("call external action %s.%s(%s);", serviceName, actionName, paramStr)
@@ -722,7 +722,7 @@ func formatAction(
722722
return fmt.Sprintf("get workflow data $%s as %s;", a.WorkflowVariable, a.Workflow)
723723

724724
case *microflows.WorkflowCallAction:
725-
if a.OutputVariableName != "" {
725+
if a.UseReturnVariable && a.OutputVariableName != "" {
726726
return fmt.Sprintf("$%s = call workflow %s ($%s);", a.OutputVariableName, a.Workflow, a.WorkflowContextVariable)
727727
}
728728
return fmt.Sprintf("call workflow %s ($%s);", a.Workflow, a.WorkflowContextVariable)
@@ -819,7 +819,7 @@ func formatAction(
819819
paramStr = strings.Join(params, ", ")
820820
}
821821

822-
if a.OutputVariableName != "" {
822+
if a.UseReturnVariable && a.OutputVariableName != "" {
823823
return fmt.Sprintf("$%s = call javascript action %s(%s);", a.OutputVariableName, jsActionName, paramStr)
824824
}
825825
return fmt.Sprintf("call javascript action %s(%s);", jsActionName, paramStr)

mdl/executor/cmd_microflows_format_action_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ func TestFormatAction_MicroflowCall_WithResult(t *testing.T) {
341341
e := newTestExecutor()
342342
action := &microflows.MicroflowCallAction{
343343
ResultVariableName: "Result",
344+
UseReturnVariable: true,
344345
MicroflowCall: &microflows.MicroflowCall{
345346
Microflow: "MyModule.ProcessOrder",
346347
ParameterMappings: []*microflows.MicroflowCallParameterMapping{
@@ -373,6 +374,7 @@ func TestFormatAction_JavaActionCall(t *testing.T) {
373374
action := &microflows.JavaActionCallAction{
374375
JavaAction: "MyModule.SendEmail",
375376
ResultVariableName: "Success",
377+
UseReturnVariable: true,
376378
ParameterMappings: []*microflows.JavaActionParameterMapping{
377379
{
378380
Parameter: "MyModule.SendEmail.To",
@@ -395,6 +397,7 @@ func TestFormatAction_CallExternal(t *testing.T) {
395397
ConsumedODataService: "MyModule.OrderService",
396398
Name: "GetOrders",
397399
ResultVariableName: "Orders",
400+
UseReturnVariable: true,
398401
}
399402
got := e.formatAction(action, nil, nil)
400403
want := "$Orders = call external action MyModule.OrderService.GetOrders();"
@@ -949,6 +952,7 @@ func TestFormatAction_JavaScriptActionCall_WithReturn(t *testing.T) {
949952
action := &microflows.JavaScriptActionCallAction{
950953
JavaScriptAction: "MyModule.MyJSAction",
951954
OutputVariableName: "Result",
955+
UseReturnVariable: true,
952956
}
953957
got := e.formatAction(action, nil, nil)
954958
want := "$Result = call javascript action MyModule.MyJSAction();"
@@ -970,6 +974,7 @@ func TestFormatAction_JavaScriptActionCall_WithParams(t *testing.T) {
970974
},
971975
},
972976
OutputVariableName: "Result",
977+
UseReturnVariable: true,
973978
}
974979
got := e.formatAction(action, nil, nil)
975980
want := "$Result = call javascript action MyModule.MyJSAction(Input = $MyVar);"
@@ -1108,6 +1113,7 @@ func TestFormatAction_JavaScriptActionCall_WithOutputAndEmptyParam(t *testing.T)
11081113
action := &microflows.JavaScriptActionCallAction{
11091114
JavaScriptAction: "MyModule.MyJSAction",
11101115
OutputVariableName: "Result",
1116+
UseReturnVariable: true,
11111117
ParameterMappings: []*microflows.JavaScriptActionParameterMapping{
11121118
{
11131119
Parameter: "MyModule.MyJSAction.Input",

0 commit comments

Comments
 (0)