Skip to content

[Workflow] WorkflowState to_json doesn't show failure details #624

@cgillum

Description

@cgillum

Expected Behavior

The to_json method of WorkflowState should include failure details in the JSON when called on for a workflow that has failed.

Actual Behavior

When calling to_json on a WorkflowState object for a failed workflow, I see valid JSON for everything except the failure_details field, which is just the generic __str__() implementation.

{
  "created_at": "2023-11-16 21:30:36.279342",
  "failure_details": "<durabletask.task.FailureDetails object at 0x7ff0a055e510>",
  "instance_id": "897b8f1c86d241d9af3908a563cd15a6",
  "last_updated_at": "2023-11-16 21:30:39.297010",
  "name": "fail_workflow",
  "runtime_status": "FAILED",
  "serialized_custom_status": null,
  "serialized_input": null,
  "serialized_output": null
}

Steps to Reproduce the Problem

The following Python code can be used to reproduce this problem:

error_test.py

from time import sleep

import dapr.ext.workflow as wf


def fail_workflow(ctx: wf.DaprWorkflowContext, _):
    raise Exception("workflow failed")


if __name__ == '__main__':
    sleep(2)

    workflowRuntime = wf.WorkflowRuntime("localhost", "50001")
    workflowRuntime.register_workflow(fail_workflow)
    workflowRuntime.start()

    wf_client = wf.DaprWorkflowClient()
    instance_id = wf_client.schedule_new_workflow(fail_workflow)
    print(f'Workflow started. Instance ID: {instance_id}')
    state = wf_client.wait_for_workflow_completion(instance_id)
    print(f'Workflow completed! Status: {state.__str__()}')

    workflowRuntime.shutdown()

requirements.txt

dapr-ext-workflow>=0.2.0

After installing the requirements, you can run the sample using the following dapr command:

dapr run --app-id wfexample --dapr-grpc-port 50001 -- python3 error_test.py

Release Note

RELEASE NOTE: FIX to_json serialization of WorkflowState for failed workflows

/cc @DeepanshuA

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions