Solve the crash on getting name of applied experiment branch

fix: #8526
1. The current `get_names` will crash if an experiment branch had
   already been given a new branch name to it.

1. Solve the crash when we getting the name of a newly fixed experiment
   branch.
2. Add a new unit test to it.
This commit is contained in:
karajan1001
2022-11-10 13:18:45 +08:00
committed by Gao
parent 49af6e1435
commit 929de7c651
2 changed files with 28 additions and 2 deletions
+1 -2
View File
@@ -248,8 +248,7 @@ def get_names(repo: "Repo", result: Dict[str, Dict[str, Any]]):
rev = baseline
if rev == "workspace":
continue
name = names.get(rev, None)
name = name or exact_name[rev]
name = names.get(rev, None) or exact_name[rev]
if name:
rev_result["data"]["name"] = name
+27
View File
@@ -0,0 +1,27 @@
from funcy import first
from scmrepo.git import Git
from dvc.repo.experiments.show import get_names
def test_get_show_branch(tmp_dir, scm: "Git", dvc, exp_stage):
new_branch = "new"
baseline = scm.get_rev()
base_branch = scm.active_branch()
results = dvc.experiments.run(exp_stage.addressing, params=["foo=2"])
exp_a = first(results)
dvc.experiments.branch(exp_a, new_branch)
scm.checkout(new_branch, force=True)
result = {
"workspace": {"baseline": {"data": {}}},
exp_a: {"baseline": {"data": {}}},
baseline: {"baseline": {"data": {}}, exp_a: {"data": {}}},
}
get_names(dvc, result)
assert result[exp_a]["baseline"]["data"] == {"name": new_branch}
assert result[baseline]["baseline"]["data"] == {"name": base_branch}
assert result[baseline][exp_a]["data"] == {"name": new_branch}