Skip to content

Commit

Permalink
IWF-372: Check if object is nil before type assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
lwolczynski committed Dec 4, 2024
1 parent 656aac8 commit b3cd703
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
9 changes: 5 additions & 4 deletions integ/wait_until_search_attributes_optimization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,18 +140,19 @@ func doTestWaitUntilHistoryCompleted(
assertions.Equal([]string{"S3", "S6"}, historyEventSAs(upsertSAEvents[7]))
assertions.Equal([]string{"S3"}, historyEventSAs(upsertSAEvents[8]))
assertions.Equal([]string{"null"}, historyEventSAs(upsertSAEvents[9]))
case iwfidl.DISABLED:
assertions.Equal(1, len(upsertSAEvents))
case iwfidl.ENABLED_FOR_STATES_WITH_WAIT_UNTIL:
default:
assertions.Equal(9, len(upsertSAEvents))
assertions.Equal([]string{"S1"}, historyEventSAs(upsertSAEvents[1]))
assertions.Equal([]string{"S2"}, historyEventSAs(upsertSAEvents[2]))
assertions.Equal([]string{"S2", "S3"}, historyEventSAs(upsertSAEvents[3]))
assertions.Equal([]string{"null"}, historyEventSAs(upsertSAEvents[2]))
assertions.Equal([]string{"S3"}, historyEventSAs(upsertSAEvents[3]))
assertions.Equal([]string{"S3", "S4"}, historyEventSAs(upsertSAEvents[4]))
assertions.Equal([]string{"S3"}, historyEventSAs(upsertSAEvents[5]))
assertions.Equal([]string{"S3", "S6"}, historyEventSAs(upsertSAEvents[6]))
assertions.Equal([]string{"S3"}, historyEventSAs(upsertSAEvents[7]))
assertions.Equal([]string{"null"}, historyEventSAs(upsertSAEvents[8]))
case iwfidl.DISABLED:
assertions.Equal(1, len(upsertSAEvents))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context) {
NextStates: []iwfidl.StateMovement{
{
StateId: State2,
StateOptions: &iwfidl.WorkflowStateOptions{
SkipWaitUntil: iwfidl.PtrBool(true),
},
},
},
},
Expand Down Expand Up @@ -192,6 +195,9 @@ func (h *handler) ApiV1WorkflowStateDecide(c *gin.Context) {
NextStates: []iwfidl.StateMovement{
{
StateId: State2,
StateOptions: &iwfidl.WorkflowStateOptions{
SkipWaitUntil: iwfidl.PtrBool(true),
},
},
{
StateId: State3,
Expand Down
14 changes: 10 additions & 4 deletions service/common/mapper/searchAttribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ func MapToInternalSearchAttributes(attributes []iwfidl.SearchAttribute) (map[str

func MapCadenceToIwfSearchAttributes(searchAttributes *shared.SearchAttributes, requestedSearchAttributes []iwfidl.SearchAttributeKeyAndType) (map[string]iwfidl.SearchAttribute, error) {
if searchAttributes == nil || len(requestedSearchAttributes) == 0 {
// return empty map rather than nil
return make(map[string]iwfidl.SearchAttribute), nil
return nil, nil
}

result := make(map[string]iwfidl.SearchAttribute, len(requestedSearchAttributes))
Expand All @@ -63,6 +62,10 @@ func MapCadenceToIwfSearchAttributes(searchAttributes *shared.SearchAttributes,
if err != nil {
return nil, err
}
// when SAs are nil, skip calling mapToIwfSearchAttribute
if object == nil {
continue
}
rv, err := mapToIwfSearchAttribute(key, sa.GetValueType(), object, true)
if err != nil {
return nil, err
Expand All @@ -75,8 +78,7 @@ func MapCadenceToIwfSearchAttributes(searchAttributes *shared.SearchAttributes,

func MapTemporalToIwfSearchAttributes(searchAttributes *common.SearchAttributes, requestedSearchAttributes []iwfidl.SearchAttributeKeyAndType) (map[string]iwfidl.SearchAttribute, error) {
if searchAttributes == nil || len(requestedSearchAttributes) == 0 {
// return empty map rather than nil
return make(map[string]iwfidl.SearchAttribute), nil
return nil, nil
}

result := make(map[string]iwfidl.SearchAttribute, len(requestedSearchAttributes))
Expand All @@ -96,6 +98,10 @@ func MapTemporalToIwfSearchAttributes(searchAttributes *common.SearchAttributes,
}
// TODO we should also call UseNumber here for JSON decoder for Temporal
// see https://github.com/temporalio/sdk-go/issues/942
// when SAs are nil, skip calling mapToIwfSearchAttribute
if object == nil {
continue
}
rv, err := mapToIwfSearchAttribute(key, sa.GetValueType(), object, false)
if err != nil {
return nil, err
Expand Down

0 comments on commit b3cd703

Please sign in to comment.