exp rename: verify exp name follows ref format

This commit is contained in:
Brady Johnson
2023-10-13 11:27:05 +09:00
committed by Peter Rowlands (변기호)
parent e5dd2bb2cc
commit c2f8115c9a
2 changed files with 13 additions and 1 deletions
+2 -1
View File
@@ -5,7 +5,7 @@ from dvc.repo.experiments.exceptions import (
ExperimentExistsError,
UnresolvedExpNamesError,
)
from dvc.repo.experiments.utils import resolve_name
from dvc.repo.experiments.utils import check_ref_format, resolve_name
from dvc.scm import Git
from .refs import ExpRefInfo
@@ -43,6 +43,7 @@ def rename(
if repo.scm.get_ref(str(new_ref)) and not force:
raise ExperimentExistsError(new_name)
check_ref_format(repo.scm, new_ref)
_rename_exp(scm=repo.scm, ref_info=result, new_name=new_name)
renamed.append(name)
+11
View File
@@ -1,5 +1,6 @@
import pytest
from dvc.exceptions import InvalidArgumentError
from dvc.repo.experiments.exceptions import (
ExperimentExistsError,
UnresolvedExpNamesError,
@@ -31,3 +32,13 @@ def test_existing_name(dvc, exp_stage):
dvc.experiments.rename("second-name", "first-name")
dvc.experiments.rename("second-name", "first-name", force=True)
def test_invalid_name(dvc, exp_stage):
dvc.experiments.run(exp_stage.addressing, name="test-name", params=["foo=1"])
with pytest.raises(InvalidArgumentError):
dvc.experiments.rename("invalid*name", "test-name")
with pytest.raises(InvalidArgumentError):
dvc.experiments.rename("invalid/name", "test-name")