From 0b2b59a601edb425c8a1ae8572be4ab4299927be Mon Sep 17 00:00:00 2001 From: skshetry Date: Mon, 5 Sep 2022 18:49:39 +0545 Subject: [PATCH] dvc.yaml: preserve outputs' desc on rewrites/updates to the stage (#8247) preserve outputs' desc on rewrites/updates to the stage We were not loading `desc` of the output, due to which we were not preserving the desc field over rewrites. Note that the rewrite only happens in select commands for `dvc.yaml`: `freeze`/`unfreeze`/`run`/`stage-add`, so we did not notice this before. --- dvc/output.py | 1 + tests/func/test_dvcfile.py | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/dvc/output.py b/dvc/output.py index d9d29fa35..4a87119fa 100644 --- a/dvc/output.py +++ b/dvc/output.py @@ -187,6 +187,7 @@ def load_from_pipeline(stage, data, typ="outs"): Output.PARAM_PERSIST, Output.PARAM_CHECKPOINT, Output.PARAM_REMOTE, + Output.PARAM_DESC, ], ) diff --git a/tests/func/test_dvcfile.py b/tests/func/test_dvcfile.py index 0ae5bb294..fdb4860f4 100644 --- a/tests/func/test_dvcfile.py +++ b/tests/func/test_dvcfile.py @@ -382,3 +382,27 @@ def test_dvcfile_try_dumping_parametrized_stage(tmp_dir, dvc, data, name): dvcfile.dump(stage) assert str(exc.value) == f"cannot dump a parametrized stage: '{name}'" + + +def test_dvcfile_load_dump_stage_with_desc_meta(tmp_dir, dvc): + data = { + "stages": { + "stage1": { + "cmd": "cp foo bar", + "desc": "stage desc", + "meta": {"key1": "value1", "key2": "value2"}, + "deps": ["foo"], + "outs": [{"bar": {"desc": "bar desc"}}], + } + } + } + (tmp_dir / "dvc.yaml").dump(data) + + stage = dvc.stage.load_one(name="stage1") + assert stage.meta == {"key1": "value1", "key2": "value2"} + assert stage.desc == "stage desc" + assert stage.outs[0].desc == "bar desc" + + # sanity check + stage.dump() + assert (tmp_dir / "dvc.yaml").parse() == data