Skip to content

Commit

Permalink
Do not use payload shorthand on workflow show
Browse files Browse the repository at this point in the history
  • Loading branch information
cretz committed Mar 25, 2024
1 parent 1e26acb commit f697225
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
10 changes: 8 additions & 2 deletions temporalcli/commands.workflow_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ func (*TemporalWorkflowCountCommand) run(*CommandContext, []string) error {
return fmt.Errorf("TODO")
}

func (c *TemporalWorkflowShowCommand) run(cctx *CommandContext, args []string) error {
func (c *TemporalWorkflowShowCommand) run(cctx *CommandContext, _ []string) error {
// Call describe
cl, err := c.Parent.ClientOptions.dialClient(cctx)
if err != nil {
Expand Down Expand Up @@ -308,7 +308,13 @@ func (c *TemporalWorkflowShowCommand) run(cctx *CommandContext, args []string) e
}
outStruct := history.History{}
outStruct.Events = events
if err := cctx.Printer.PrintStructured(&outStruct, printer.StructuredOptions{}); err != nil {
// We intentionally disable shorthand because "workflow show" for JSON needs
// to support SDK replayers which do not work with shorthand
jsonPayloadShorthand := false
err = cctx.Printer.PrintStructured(&outStruct, printer.StructuredOptions{
OverrideJSONPayloadShorthand: &jsonPayloadShorthand,
})
if err != nil {
return fmt.Errorf("failed printing structured output: %w", err)
}
}
Expand Down
5 changes: 4 additions & 1 deletion temporalcli/commands.workflow_view_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package temporalcli_test

import (
"context"
"encoding/base64"
"encoding/json"
"fmt"
"strconv"
Expand Down Expand Up @@ -256,7 +257,7 @@ func (s *SharedServerSuite) TestWorkflow_Show_JSON() {
s.Context,
client.StartWorkflowOptions{TaskQueue: s.Worker.Options.TaskQueue},
DevWorkflow,
"ignored",
"workflow-param",
)
s.NoError(err)

Expand All @@ -270,6 +271,8 @@ func (s *SharedServerSuite) TestWorkflow_Show_JSON() {
out := res.Stdout.String()
s.Contains(out, `"events": [`)
s.Contains(out, `"eventType": "EVENT_TYPE_WORKFLOW_EXECUTION_STARTED"`)
// Make sure payloads are still encoded non-shorthand
s.Contains(out, base64.StdEncoding.EncodeToString([]byte(`"workflow-param"`)))

// Send signals to complete
s.NoError(s.Client.SignalWorkflow(s.Context, run.GetID(), "", "my-signal", nil))
Expand Down
3 changes: 2 additions & 1 deletion temporalcli/commandsmd/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,8 @@ Use the options listed below to change reset behavior.
### temporal workflow show: Show Event History for a Workflow Execution.

The `temporal workflow show` command provides the [Event History](/concepts/what-is-an-event-history) for a
[Workflow Execution](/concepts/what-is-a-workflow-execution).
[Workflow Execution](/concepts/what-is-a-workflow-execution). With JSON output specified, this output can be given to
an SDK to perform a replay.

Use the options listed below to change the command's behavior.

Expand Down

0 comments on commit f697225

Please sign in to comment.