Skip to content

Commit 860b601

Browse files
committed
Fix SQL max workflow ID validation
1 parent 44c7b2b commit 860b601

3 files changed

Lines changed: 132 additions & 1 deletion

File tree

config/dynamicconfig/development-sql.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
### END of Worker Versioning Replay Test configs
4444

4545
limit.maxIDLength:
46-
- value: 255
46+
- value: 1000
4747
constraints: {}
4848
frontend.workerVersioningDataAPIs:
4949
- value: true

service/history/api/command_attr_validator_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package api
33
import (
44
"fmt"
55
"math/rand"
6+
"strings"
67
"testing"
78
"time"
89

@@ -842,6 +843,57 @@ func (s *commandAttrValidatorSuite) TestValidateStartChildExecutionAttributes_In
842843
}
843844
}
844845

846+
func (s *commandAttrValidatorSuite) TestValidateStartChildExecutionAttributes_WorkflowIDLengthLimit() {
847+
parentInfo := &persistencespb.WorkflowExecutionInfo{
848+
TaskQueue: "test-parent-task-queue",
849+
WorkflowId: "test-parent-wf-id",
850+
WorkflowTypeName: "test-parent-wf-type",
851+
}
852+
853+
for _, tt := range []struct {
854+
name string
855+
workflowID string
856+
expectError bool
857+
}{
858+
{
859+
name: "limit accepted",
860+
workflowID: strings.Repeat("a", 1000),
861+
},
862+
{
863+
name: "over limit rejected",
864+
workflowID: strings.Repeat("a", 1001),
865+
expectError: true,
866+
},
867+
} {
868+
s.Run(tt.name, func() {
869+
attributes := &commandpb.StartChildWorkflowExecutionCommandAttributes{
870+
WorkflowId: tt.workflowID,
871+
WorkflowType: &commonpb.WorkflowType{
872+
Name: "test-child-wf-type",
873+
},
874+
TaskQueue: &taskqueuepb.TaskQueue{
875+
Name: "test-child-task-queue",
876+
},
877+
Namespace: "test-ns",
878+
}
879+
_, err := s.validator.ValidateStartChildExecutionAttributes(
880+
s.testNamespaceID,
881+
s.testNamespaceID,
882+
namespace.Name("test-ns"),
883+
attributes,
884+
parentInfo,
885+
dynamicconfig.GetDurationPropertyFnFilteredByNamespace(time.Second),
886+
)
887+
888+
if tt.expectError {
889+
s.ErrorContains(err, "WorkflowId on StartChildWorkflowExecutionCommand exceeds length limit")
890+
} else {
891+
s.NoError(err)
892+
}
893+
})
894+
}
895+
}
896+
845897
func (s *commandAttrValidatorSuite) TestValidateActivityScheduleAttributes_WorkflowTaskQueue() {
846898
testCases := []struct {
847899
name string

tests/child_workflow_test.go

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package tests
33
import (
44
"fmt"
55
"sort"
6+
"strings"
67
"testing"
78
"time"
89

@@ -1244,3 +1245,81 @@ func (s *ChildWorkflowSuite) TestStartChildWorkflowWithInternalTaskQueue_Blocked
12441245
}
12451246
s.True(foundTaskFailed, "WorkflowTaskFailed event should be recorded")
12461247
}
1248+
1249+
func (s *ChildWorkflowSuite) TestStartChildWorkflowWithMaxLengthWorkflowID() {
1250+
parentID := testcore.RandomizeStr(s.T().Name())
1251+
childID := strings.Repeat("w", 1000)
1252+
wtParent := "test-child-workflow-max-id-parent-type"
1253+
wtChild := "test-child-workflow-max-id-child-type"
1254+
tlParent := "test-child-workflow-max-id-parent-taskqueue"
1255+
tlChild := "test-child-workflow-max-id-child-taskqueue"
1256+
identity := "worker1"
1257+
1258+
parentWorkflowType := &commonpb.WorkflowType{Name: wtParent}
1259+
childWorkflowType := &commonpb.WorkflowType{Name: wtChild}
1260+
taskQueueParent := &taskqueuepb.TaskQueue{Name: tlParent, Kind: enumspb.TASK_QUEUE_KIND_NORMAL}
1261+
taskQueueChild := &taskqueuepb.TaskQueue{Name: tlChild, Kind: enumspb.TASK_QUEUE_KIND_NORMAL}
1262+
1263+
request := &workflowservice.StartWorkflowExecutionRequest{
1264+
RequestId: uuid.NewString(),
1265+
Namespace: s.Namespace().String(),
1266+
WorkflowId: parentID,
1267+
WorkflowType: parentWorkflowType,
1268+
TaskQueue: taskQueueParent,
1269+
Input: nil,
1270+
WorkflowRunTimeout: durationpb.New(100 * time.Second),
1271+
WorkflowTaskTimeout: durationpb.New(10 * time.Second),
1272+
Identity: identity,
1273+
}
1274+
1275+
we, err := s.FrontendClient().StartWorkflowExecution(testcore.NewContext(), request)
1276+
s.NoError(err)
1277+
s.Logger.Info("StartWorkflowExecution", tag.WorkflowRunID(we.RunId))
1278+
1279+
childExecutionStarted := false
1280+
wtHandlerParent := func(task *workflowservice.PollWorkflowTaskQueueResponse) (*workflowservice.RespondWorkflowTaskCompletedRequest, error) {
1281+
for _, event := range task.GetHistory().GetEvents() {
1282+
if event.GetEventType() == enumspb.EVENT_TYPE_CHILD_WORKFLOW_EXECUTION_STARTED {
1283+
attrs := event.GetChildWorkflowExecutionStartedEventAttributes()
1284+
s.Equal(childID, attrs.GetWorkflowExecution().GetWorkflowId())
1285+
childExecutionStarted = true
1286+
return &workflowservice.RespondWorkflowTaskCompletedRequest{}, nil
1287+
}
1288+
}
1289+
1290+
return &workflowservice.RespondWorkflowTaskCompletedRequest{
1291+
Commands: []*commandpb.Command{{
1292+
CommandType: enumspb.COMMAND_TYPE_START_CHILD_WORKFLOW_EXECUTION,
1293+
Attributes: &commandpb.Command_StartChildWorkflowExecutionCommandAttributes{
1294+
StartChildWorkflowExecutionCommandAttributes: &commandpb.StartChildWorkflowExecutionCommandAttributes{
1295+
WorkflowId: childID,
1296+
WorkflowType: childWorkflowType,
1297+
TaskQueue: taskQueueChild,
1298+
Input: payloads.EncodeString("child-workflow-input"),
1299+
WorkflowRunTimeout: durationpb.New(200 * time.Second),
1300+
WorkflowTaskTimeout: durationpb.New(2 * time.Second),
1301+
},
1302+
},
1303+
}},
1304+
}, nil
1305+
}
1306+
1307+
pollerParent := taskpoller.New(s.T(), s.FrontendClient(), s.Namespace().String())
1308+
tvParent := testvars.New(s.T()).WithWorkflowID(parentID).WithTaskQueue(tlParent)
1309+
1310+
_, err = pollerParent.PollAndHandleWorkflowTask(tvParent, wtHandlerParent)
1311+
s.NoError(err)
1312+
_, err = pollerParent.PollAndHandleWorkflowTask(tvParent, wtHandlerParent, taskpoller.WithTimeout(15*time.Second))
1313+
s.NoError(err)
1314+
s.True(childExecutionStarted)
1315+
1316+
describeResp, err := s.FrontendClient().DescribeWorkflowExecution(testcore.NewContext(), &workflowservice.DescribeWorkflowExecutionRequest{
1317+
Namespace: s.Namespace().String(),
1318+
Execution: &commonpb.WorkflowExecution{
1319+
WorkflowId: childID,
1320+
},
1321+
})
1322+
s.NoError(err)
1323+
s.Equal(childID, describeResp.GetWorkflowExecutionInfo().GetExecution().GetWorkflowId())
1324+
s.Equal(enumspb.WORKFLOW_EXECUTION_STATUS_RUNNING, describeResp.GetWorkflowExecutionInfo().GetStatus())
1325+
}

0 commit comments

Comments
 (0)