[workflow] fix workflow user metadata return when None is given (#19356)

## Why are these changes needed?

Quick fix for metadata put. Currently when workflow-level metadata is not given, it will output `null` to `user_run_metadata.json`, this fix will make it output `{}`.
## Related issue number

original issue: https://github.com/ray-project/ray/issues/17090
original PR: https://github.com/ray-project/ray/pull/19195
This commit is contained in:
Linsong Chu 2021-10-13 18:52:12 -04:00 committed by GitHub
parent 1dc03cd49d
commit b86a5fcb96
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View file

@ -37,6 +37,7 @@ def run(entry_workflow: Workflow,
raise ValueError("metadata values must be JSON serializable, "
"however '{}' has a value whose {}.".format(
k, e))
metadata = metadata or {}
store = get_global_storage()
assert ray.is_initialized()

View file

@ -86,6 +86,25 @@ def test_workflow_runtime_metadata(workflow_start_regular):
assert "end_time" in postrun_meta
def test_no_user_metadata(workflow_start_regular):
workflow_id = "simple"
step_name = "simple_step"
@workflow.step(name=step_name)
def simple():
return 0
simple.step().run(workflow_id)
checkpointed_user_step_metadata = get_metadata(
[workflow_id, "steps", step_name, workflow_storage.STEP_USER_METADATA])
checkpointed_user_run_metadata = get_metadata(
[workflow_id, workflow_storage.WORKFLOW_USER_METADATA])
assert {} == checkpointed_user_step_metadata
assert {} == checkpointed_user_run_metadata
def test_all_metadata(workflow_start_regular):
user_step_metadata = {"k1": "v1"}