Skip to content

Commit

Permalink
Fix panic when calling GetWorkflow (#333)
Browse files Browse the repository at this point in the history
* Fix panic when calling `GetWorkflow` with no run id when that workflow has never run before
  • Loading branch information
Sushisource authored Jan 12, 2021
1 parent 1c882f7 commit 67d8f3b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
14 changes: 9 additions & 5 deletions internal/internal_workflow_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ type (
// GetID return workflow ID, which will be same as StartWorkflowOptions.ID if provided.
GetID() string

// GetRunID return the first started workflow run ID (please see below)
// GetRunID return the first started workflow run ID (please see below) - empty string if no such run
GetRunID() string

// Get will fill the workflow execution result to valuePtr,
Expand Down Expand Up @@ -311,11 +311,15 @@ func (wc *WorkflowClient) GetWorkflow(ctx context.Context, workflowID string, ru
var runIDCell util.OnceCell
if runID == "" {
fetcher := func() string {
execData, err := wc.DescribeWorkflowExecution(ctx, workflowID, runID)
if err != nil {
wc.logger.Error("error while fetching workflow execution info", err)
execData, _ := wc.DescribeWorkflowExecution(ctx, workflowID, runID)
wei := execData.GetWorkflowExecutionInfo()
if wei != nil {
execution := wei.GetExecution()
if execution != nil {
return execution.RunId
}
}
return execData.GetWorkflowExecutionInfo().GetExecution().RunId
return ""
}
runIDCell = util.LazyOnceCell(fetcher)
} else {
Expand Down
13 changes: 13 additions & 0 deletions internal/internal_workflow_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"time"

workflowpb "go.temporal.io/api/workflow/v1"

ilog "go.temporal.io/sdk/internal/log"

"github.com/golang/mock/gomock"
Expand Down Expand Up @@ -952,6 +953,18 @@ func (s *workflowRunSuite) TestGetWorkflowNoRunId() {
s.Equal(runID, workflowRunNoRunID.GetRunID())
}

func (s *workflowRunSuite) TestGetWorkflowNoExtantWorkflowAndNoRunId() {
describeResp := &workflowservice.DescribeWorkflowExecutionResponse{
WorkflowExecutionInfo: nil}
s.workflowServiceClient.EXPECT().DescribeWorkflowExecution(gomock.Any(), gomock.Any(), gomock.Any()).Return(describeResp, nil).Times(1)
workflowRunNoRunID := s.workflowClient.GetWorkflow(
context.Background(),
workflowID,
"",
)
s.Equal("", workflowRunNoRunID.GetRunID())
}

func getGetWorkflowExecutionHistoryRequest(filterType enumspb.HistoryEventFilterType) *workflowservice.GetWorkflowExecutionHistoryRequest {
request := &workflowservice.GetWorkflowExecutionHistoryRequest{
Namespace: DefaultNamespace,
Expand Down

0 comments on commit 67d8f3b

Please sign in to comment.