From 3427e115ebadaa16dad63afdfd0517bd7b32667d Mon Sep 17 00:00:00 2001 From: skshetry <18718008+skshetry@users.noreply.github.com> Date: Wed, 25 Jan 2023 18:09:38 +0545 Subject: [PATCH] data status: check if change.old.hash_info is None or not (#8878) data:status: check if change.old.hash_info is None or not --- dvc/repo/data.py | 1 + tests/func/test_data_status.py | 28 +++++++++++++++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/dvc/repo/data.py b/dvc/repo/data.py index 7b035eb23..2dbd40575 100644 --- a/dvc/repo/data.py +++ b/dvc/repo/data.py @@ -93,6 +93,7 @@ def _diff( if ( with_missing and change.old + and change.old.hash_info and not change.old.odb.exists(change.old.hash_info.value) ): # NOTE: emulating previous behaviour diff --git a/tests/func/test_data_status.py b/tests/func/test_data_status.py index 6793f9fce..87d0b3206 100644 --- a/tests/func/test_data_status.py +++ b/tests/func/test_data_status.py @@ -176,10 +176,32 @@ def test_skip_uncached_pipeline_outputs(tmp_dir, dvc, run_copy_metrics): ) -def test_output_with_newly_added_stage(tmp_dir, dvc): +def test_outs_with_no_hashes(M, tmp_dir, dvc, scm): + dvc.stage.add(single_stage=True, outs=["bar"]) dvc.stage.add(deps=["bar"], outs=["foo"], name="copy", cmd="cp foo bar") - assert dvc.data_status() == EMPTY_STATUS - assert dvc.data_status(granular=True) == EMPTY_STATUS + + expected_output = { + **EMPTY_STATUS, + "committed": {"added": M.unordered("bar", "foo")}, + "git": M.dict(), + } + assert dvc.data_status() == expected_output + assert dvc.data_status(granular=True) == expected_output + + +def test_outs_with_no_hashes_and_with_uncommitted_files(M, tmp_dir, dvc, scm): + tmp_dir.gen({"bar": "bar", "foo": "foo"}) + dvc.stage.add(single_stage=True, outs=["bar"]) + dvc.stage.add(deps=["bar"], outs=["foo"], name="copy", cmd="cp foo bar") + + expected_output = { + **EMPTY_STATUS, + "uncommitted": {"added": M.unordered("bar", "foo")}, + "committed": {"added": M.unordered("bar", "foo")}, + "git": M.dict(), + } + assert dvc.data_status() == expected_output + assert dvc.data_status(granular=True) == expected_output def test_subdir(M, tmp_dir, scm):