Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use data converter if search attribute value is of Payload type #913

Merged
merged 2 commits into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions internal/internal_workflow_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
22 changes: 19 additions & 3 deletions internal/internal_workflow_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down