diff --git a/dvc/repo/plots/__init__.py b/dvc/repo/plots/__init__.py index fe526d2891..7fcae7fd19 100644 --- a/dvc/repo/plots/__init__.py +++ b/dvc/repo/plots/__init__.py @@ -462,11 +462,12 @@ def _resolve_definitions( fs, data_path, props=plot_props | props, onerror=onerror ) # use config for parent directory with most specific definition - unpacked["data"] = { - k: v - for k, v in unpacked["data"].items() - if _closest_parent(fs, k, plot_ids_parents) == data_path - } + if unpacked.get("data"): + unpacked["data"] = { + k: v + for k, v in unpacked["data"].items() + if _closest_parent(fs, k, plot_ids_parents) == data_path + } dpath.merge(result, unpacked) elif _matches(targets, config_path, plot_id): adjusted_props = _adjust_sources(fs, plot_props, config_dir) diff --git a/tests/integration/plots/test_plots.py b/tests/integration/plots/test_plots.py index d53c5a467b..c41ec86576 100644 --- a/tests/integration/plots/test_plots.py +++ b/tests/integration/plots/test_plots.py @@ -634,3 +634,15 @@ def test_nested_x_defn_collection(tmp_dir, dvc, scm, capsys): {"step": 1, "Max_Leaf_Nodes": "50", "rev": "workspace"}, {"step": 2, "Max_Leaf_Nodes": "500", "rev": "workspace"}, ] + + +def test_plots_empty_directory(tmp_dir, dvc, scm, capsys): + (tmp_dir / "empty").mkdir() + (tmp_dir / "dvc.yaml").dump({"plots": [{"empty": {}}]}) + + scm.add(["dvc.yaml"]) + scm.commit("commit dvc files") + + html_path, _, split_json_result = call(capsys) + assert split_json_result == {} + assert html_path == ""