Skip to content

Commit d68db26

Browse files
Apply context to data converter in update (#1991)
1 parent 8ee3a8a commit d68db26

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

internal/internal_workflow_client.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2400,7 +2400,11 @@ func (w *workflowClientInterceptor) createUpdateWorkflowRequest(
24002400
ctx context.Context,
24012401
in *ClientUpdateWorkflowInput,
24022402
) (*workflowservice.UpdateWorkflowExecutionRequest, error) {
2403-
argPayloads, err := w.client.dataConverter.ToPayloads(in.Args...)
2403+
dataConverter := WithContext(ctx, w.client.dataConverter)
2404+
if dataConverter == nil {
2405+
dataConverter = converter.GetDefaultDataConverter()
2406+
}
2407+
argPayloads, err := dataConverter.ToPayloads(in.Args...)
24042408
if err != nil {
24052409
return nil, err
24062410
}

internal/internal_workflow_client_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,6 +1471,36 @@ func (s *workflowClientTestSuite) TestSignalWithStartWorkflowWithContextAwareDat
14711471
s.Equal(startResponse.GetRunId(), resp.GetRunID())
14721472
}
14731473

1474+
func (s *workflowClientTestSuite) TestUpdateWorkflowWithContextAwareDataConverter() {
1475+
dc := NewContextAwareDataConverter(converter.GetDefaultDataConverter())
1476+
s.client = NewServiceClient(s.service, nil, ClientOptions{DataConverter: dc})
1477+
client, ok := s.client.(*WorkflowClient)
1478+
s.True(ok)
1479+
1480+
input := "test"
1481+
1482+
updateResponse := &workflowservice.UpdateWorkflowExecutionResponse{
1483+
Stage: enumspb.UPDATE_WORKFLOW_EXECUTION_LIFECYCLE_STAGE_COMPLETED,
1484+
Outcome: &updatepb.Outcome{
1485+
Value: &updatepb.Outcome_Success{},
1486+
},
1487+
}
1488+
s.service.EXPECT().UpdateWorkflowExecution(gomock.Any(), gomock.Any(), gomock.Any()).Return(updateResponse, nil).Do(func(_ interface{}, req *workflowservice.UpdateWorkflowExecutionRequest, _ ...interface{}) {
1489+
dc := client.dataConverter
1490+
inputs := dc.ToStrings(req.GetRequest().GetInput().Args)
1491+
s.Equal("\"te?t\"", inputs[0])
1492+
})
1493+
ctx := context.Background()
1494+
ctx = context.WithValue(ctx, ContextAwareDataConverterContextKey, "s")
1495+
1496+
_, err := s.client.UpdateWorkflow(ctx, UpdateWorkflowOptions{
1497+
UpdateName: "my-update",
1498+
WaitForStage: WorkflowUpdateStageCompleted,
1499+
Args: []interface{}{input},
1500+
})
1501+
s.Nil(err)
1502+
}
1503+
14741504
func (s *workflowClientTestSuite) TestSignalWithStartWorkflowValidation() {
14751505
// ambiguous WorkflowID
14761506
_, err := s.client.SignalWithStartWorkflow(

0 commit comments

Comments
 (0)