From 198c8f2ffd8ad63d7009e5468f99755a571829c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Michel?= Date: Sun, 1 Dec 2024 17:21:46 +0100 Subject: [PATCH] Fix #10638 : makes remove return correct list when used with both `--queue` and `-A` (#10641) * fixed a bug where using both `--queue` and `-A` would yield a "removed" list without the queued experiments * added a test to validate the fix * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * clearer name for test --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- dvc/repo/experiments/remove.py | 2 +- tests/func/experiments/test_remove.py | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/dvc/repo/experiments/remove.py b/dvc/repo/experiments/remove.py index cd8ca07e8b..1b29f30255 100644 --- a/dvc/repo/experiments/remove.py +++ b/dvc/repo/experiments/remove.py @@ -75,7 +75,7 @@ def remove( # noqa: C901, PLR0912 exp_ref_list.extend(exp_ref_dict.values()) elif all_commits: exp_ref_list.extend(exp_refs(repo.scm, git_remote)) - removed = [ref.name for ref in exp_ref_list] + removed.extend([ref.name for ref in exp_ref_list]) if keep: exp_ref_list = list(set(exp_refs(repo.scm, git_remote)) - set(exp_ref_list)) diff --git a/tests/func/experiments/test_remove.py b/tests/func/experiments/test_remove.py index 1864cc541d..8dd2b65498 100644 --- a/tests/func/experiments/test_remove.py +++ b/tests/func/experiments/test_remove.py @@ -43,6 +43,26 @@ def test_remove_all_queued_experiments(tmp_dir, scm, dvc, exp_stage): assert scm.get_ref(str(ref_info)) is not None +def test_remove_all_experiments_queued_and_completed(tmp_dir, scm, dvc, exp_stage): + queue_length = 3 + for i in range(queue_length): + dvc.experiments.run( + exp_stage.addressing, params=[f"foo={i}"], name=f"exp{i}", queue=True + ) + + results = dvc.experiments.run( + exp_stage.addressing, params=[f"foo={queue_length}"], name=f"exp{queue_length}" + ) + ref_info = first(exp_refs_by_rev(scm, first(results))) + + removed = sorted(dvc.experiments.remove(all_commits=True, queue=True)) + + assert len(removed) == queue_length + 1 + assert removed == [f"exp{i}" for i in range(queue_length)] + [ref_info.name] + assert len(dvc.experiments.stash_revs) == 0 + assert scm.get_ref(str(ref_info)) is None + + def test_remove_special_queued_experiments(tmp_dir, scm, dvc, exp_stage): dvc.experiments.run( exp_stage.addressing, params=["foo=1"], queue=True, name="queue1"