Skip to content

Commit b13a953

Browse files
authored
Add SearchAttributes.Copy exception to workflowcheck (#1958)
* SearchAttributes.Copy exception * Add test, mark Copy with workflowcheck:ignore directly
1 parent 46420c2 commit b13a953

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

contrib/tools/workflowcheck/workflow/testdata/src/a/workflow.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"text/template"
66
"time"
77

8+
"go.temporal.io/sdk/temporal"
89
"go.temporal.io/sdk/workflow"
910
)
1011

@@ -66,3 +67,8 @@ func WorkflowWithUnnamedArgument(workflow.Context) error { // want "a.WorkflowWi
6667
func NotWorkflow(ctx context.Context) {
6768
time.Now()
6869
}
70+
71+
func WorkflowWithSearchAttributes(workflow.Context) {
72+
sa := temporal.SearchAttributes{}
73+
_ = sa.Copy()
74+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package temporal
2+
3+
// This file somewhat mirrors the internal SearchAttributes implementation. The purpose of this is to
4+
// test SearchAttributes.Copy()'s map iteration being ignored with `//workflowcheck:ignore`
5+
6+
type (
7+
SearchAttributeKey interface{}
8+
9+
// SearchAttributes represents a collection of typed search attributes
10+
SearchAttributes struct {
11+
untypedValue map[SearchAttributeKey]interface{}
12+
}
13+
14+
// SearchAttributeUpdate represents a change to SearchAttributes
15+
SearchAttributeUpdate func(*SearchAttributes)
16+
)
17+
18+
// GetUntypedValues gets a copy of the collection with raw types.
19+
func (sa SearchAttributes) GetUntypedValues() map[SearchAttributeKey]interface{} {
20+
untypedValueCopy := make(map[SearchAttributeKey]interface{}, len(sa.untypedValue))
21+
for key, value := range sa.untypedValue {
22+
// Filter out nil values
23+
if value == nil {
24+
continue
25+
}
26+
switch v := value.(type) {
27+
case []string:
28+
untypedValueCopy[key] = append([]string(nil), v...)
29+
default:
30+
untypedValueCopy[key] = v
31+
}
32+
}
33+
return untypedValueCopy
34+
}
35+
36+
// Copy creates an update that copies existing values.
37+
//
38+
//workflowcheck:ignore
39+
func (sa SearchAttributes) Copy() SearchAttributeUpdate {
40+
return func(s *SearchAttributes) {
41+
// GetUntypedValues returns a copy of the map without nil values
42+
// so the copy won't delete any existing values
43+
untypedValues := sa.GetUntypedValues()
44+
for key, value := range untypedValues {
45+
s.untypedValue[key] = value
46+
}
47+
}
48+
}

internal/internal_search_attributes.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,8 @@ func (sa SearchAttributes) GetUntypedValues() map[SearchAttributeKey]interface{}
361361
}
362362

363363
// Copy creates an update that copies existing values.
364+
//
365+
//workflowcheck:ignore
364366
func (sa SearchAttributes) Copy() SearchAttributeUpdate {
365367
return func(s *SearchAttributes) {
366368
// GetUntypedValues returns a copy of the map without nil values

0 commit comments

Comments
 (0)