From bd9df677f14770e27aecece70de7e26798e76361 Mon Sep 17 00:00:00 2001 From: Alex Shtin Date: Fri, 16 Sep 2022 17:38:28 -0700 Subject: [PATCH 1/2] Don't use data converter if search attribute value is of Payload type --- internal/internal_workflow_client.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/internal/internal_workflow_client.go b/internal/internal_workflow_client.go index 54b1955c4..3f0f22880 100644 --- a/internal/internal_workflow_client.go +++ b/internal/internal_workflow_client.go @@ -1214,11 +1214,17 @@ func serializeSearchAttributes(input map[string]interface{}) (*commonpb.SearchAt attr := make(map[string]*commonpb.Payload) for k, v := range input { - attrBytes, err := converter.GetDefaultDataConverter().ToPayload(v) + // If search attribute value is already of Payload type, then use it directly. + // This allows to copy search attributes from workflow info to child workflow options. + if vp, ok := v.(*commonpb.Payload); ok { + attr[k] = vp + continue + } + var err error + attr[k], err = converter.GetDefaultDataConverter().ToPayload(v) if err != nil { return nil, fmt.Errorf("encode search attribute [%s] error: %v", k, err) } - attr[k] = attrBytes } return &commonpb.SearchAttributes{IndexedFields: attr}, nil } From 0596f746fce8593f8449506e1939029ef6b13387 Mon Sep 17 00:00:00 2001 From: Alex Shtin Date: Mon, 19 Sep 2022 13:52:50 -0700 Subject: [PATCH 2/2] Add unit tests --- internal/internal_workflow_client_test.go | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/internal/internal_workflow_client_test.go b/internal/internal_workflow_client_test.go index ad818ad89..d350117ce 100644 --- a/internal/internal_workflow_client_test.go +++ b/internal/internal_workflow_client_test.go @@ -1288,17 +1288,33 @@ func (s *workflowClientTestSuite) TestSerializeSearchAttributes() { s.NotNil(result2) s.Equal(0, len(result2.IndexedFields)) - input1["t1"] = "v1" + input1 = map[string]interface{}{ + "t1": "v1", + } result3, err := serializeSearchAttributes(input1) s.NoError(err) s.NotNil(result3) s.Equal(1, len(result3.IndexedFields)) var resultString string - _ = converter.GetDefaultDataConverter().FromPayload(result3.IndexedFields["t1"], &resultString) s.Equal("v1", resultString) - input1["non-serializable"] = make(chan int) + // *Payload type goes through. + p, err := converter.GetDefaultDataConverter().ToPayload("5eaf00d") + s.NoError(err) + input1 = map[string]interface{}{ + "payload": p, + } + result4, err := serializeSearchAttributes(input1) + s.NoError(err) + s.NotNil(result3) + s.Equal(1, len(result3.IndexedFields)) + _ = converter.GetDefaultDataConverter().FromPayload(result4.IndexedFields["payload"], &resultString) + s.Equal("5eaf00d", resultString) + + input1 = map[string]interface{}{ + "non-serializable": make(chan int), + } _, err = serializeSearchAttributes(input1) s.Error(err) }