Skip to content

Commit

Permalink
Fallback to zero value for non-present parent execution fields (#4617)
Browse files Browse the repository at this point in the history
  • Loading branch information
vytautas-karpavicius authored and Shaddoll committed Nov 4, 2021
1 parent 49df671 commit 4b95ec8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
20 changes: 6 additions & 14 deletions common/types/mapper/proto/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -4501,25 +4501,17 @@ func FromParentExecutionInfoFields(domainID, domainName *string, we *types.Workf
if domainID == nil && domainName == nil && we == nil && initiatedID == nil {
return nil
}
if domainName == nil || we == nil || initiatedID == nil {
panic("either all or none parent execution info must be set")
}

// Domain ID was added to unify parent execution info in several places.
// However it may not be present:
// ParentExecutionInfo wrapper was added to unify parent related fields.
// However some fields may not be present:
// - on older histories
// - if conversion involves thrift data types
// Fallback to empty string in those cases
parentDomainID := ""
if domainID != nil {
parentDomainID = *domainID
}

// Fallback to zero values in those cases
return &apiv1.ParentExecutionInfo{
DomainId: parentDomainID,
DomainName: *domainName,
DomainId: common.StringDefault(domainID),
DomainName: common.StringDefault(domainName),
WorkflowExecution: FromWorkflowExecution(we),
InitiatedId: *initiatedID,
InitiatedId: common.Int64Default(initiatedID),
}
}

Expand Down
11 changes: 8 additions & 3 deletions common/types/mapper/proto/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -769,12 +769,17 @@ func TestParentExecutionInfo(t *testing.T) {
}
func TestParentExecutionInfoFields(t *testing.T) {
assert.Nil(t, FromParentExecutionInfoFields(nil, nil, nil, nil))
assert.Panics(t, func() { FromParentExecutionInfoFields(nil, &testdata.ParentExecutionInfo.Domain, nil, nil) })
info := FromParentExecutionInfoFields(nil,
info := FromParentExecutionInfoFields(nil, nil, testdata.ParentExecutionInfo.Execution, nil)
assert.Equal(t, "", *ToParentDomainID(info))
assert.Equal(t, "", *ToParentDomainName(info))
assert.Equal(t, testdata.ParentExecutionInfo.Execution, ToParentWorkflowExecution(info))
assert.Equal(t, int64(0), *ToParentInitiatedID(info))
info = FromParentExecutionInfoFields(
&testdata.ParentExecutionInfo.DomainUUID,
&testdata.ParentExecutionInfo.Domain,
testdata.ParentExecutionInfo.Execution,
&testdata.ParentExecutionInfo.InitiatedID)
assert.Equal(t, "", *ToParentDomainID(info))
assert.Equal(t, testdata.ParentExecutionInfo.DomainUUID, *ToParentDomainID(info))
assert.Equal(t, testdata.ParentExecutionInfo.Domain, *ToParentDomainName(info))
assert.Equal(t, testdata.ParentExecutionInfo.Execution, ToParentWorkflowExecution(info))
assert.Equal(t, testdata.ParentExecutionInfo.InitiatedID, *ToParentInitiatedID(info))
Expand Down

0 comments on commit 4b95ec8

Please sign in to comment.