Skip to content

Commit 2e77f05

Browse files
fix(parsing): was trying to load params.yaml twice and even when it didn't exist
1 parent 71686bf commit 2e77f05

File tree

2 files changed

+9
-35
lines changed

2 files changed

+9
-35
lines changed

dvc/parsing/context.py

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -498,34 +498,6 @@ def _load_default_params_file(self, fs, wdir: str):
498498
data = read_param_file(fs, default_path, key_paths=None, flatten=False)
499499
self._merge_params_data(data, default_path)
500500

501-
def _load_params_from_string(self, fs, item: str, wdir: str):
502-
"""Load params from a string item (file path or file:keys format)."""
503-
from dvc.dependency.param import read_param_file
504-
from dvc.parsing.interpolate import is_interpolated_string
505-
506-
# Skip vars interpolations (but allow plain paths and ${param.*})
507-
if is_interpolated_string(item) and not is_params_interpolation(item):
508-
return
509-
510-
# Skip param keys (they're handled by loading default file)
511-
if "/" not in item and "\\" not in item and ":" not in item:
512-
return
513-
514-
# Parse file path and keys
515-
if ":" in item:
516-
file_path, _, keys_str = item.partition(":")
517-
keys = lfilter(bool, keys_str.split(",")) if keys_str else None
518-
else:
519-
file_path = item
520-
keys = None
521-
522-
path = fs.normpath(fs.join(wdir, file_path))
523-
if not fs.exists(path):
524-
raise ParamsLoadError(f"'{path}' does not exist")
525-
526-
data = read_param_file(fs, path, key_paths=keys, flatten=False)
527-
self._merge_params_data(data, path)
528-
529501
def _load_params_from_dict(self, fs, item: dict, wdir: str):
530502
"""Load params from a dict item (file: keys mapping)."""
531503
from dvc.dependency.param import read_param_file
@@ -562,14 +534,14 @@ def load_params(self, fs, params_list: list, wdir: str):
562534
if self._params_context is None:
563535
self._params_context = CtxDict(meta=Meta(source="params", local=False))
564536

565-
# Always load default params file if it exists
537+
# Load default params file if it exists (for ${param.*} interpolation)
566538
self._load_default_params_file(fs, wdir)
567539

568540
# Process each item in params list
541+
# Note: String items are param KEYS for dependency tracking, not files
542+
# Only dict items specify files to load for ${param.*} interpolation
569543
for item in params_list:
570-
if isinstance(item, str):
571-
self._load_params_from_string(fs, item, wdir)
572-
elif isinstance(item, dict):
544+
if isinstance(item, dict):
573545
self._load_params_from_dict(fs, item, wdir)
574546

575547
def _merge_params_data(self, data: dict, source_path: str):

tests/func/parsing/test_params_templating.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,16 @@ def test_params_in_outs(self, tmp_dir, dvc):
6565
"train": {
6666
"cmd": "python train.py",
6767
"outs": [f"${{{PARAMS_NAMESPACE}.model_path}}"],
68-
"params": [DEFAULT_PARAMS_FILE],
68+
"params": [{DEFAULT_PARAMS_FILE: []}],
6969
}
7070
}
7171
}
7272

73+
resolver = DataResolver(dvc, tmp_dir.fs_path, dvc_yaml)
7374
with pytest.raises(
7475
ResolveError, match="interpolation is not allowed in 'outs'"
7576
):
76-
DataResolver(dvc, tmp_dir.fs_path, dvc_yaml)
77+
resolver.resolve()
7778

7879
def test_params_nested_dict_access(self, tmp_dir, dvc):
7980
"""
@@ -935,10 +936,11 @@ def test_all_namespaces_in_outs(self, tmp_dir, dvc):
935936
},
936937
}
937938

939+
resolver = DataResolver(dvc, tmp_dir.fs_path, dvc_yaml)
938940
with pytest.raises(
939941
ResolveError, match="interpolation is not allowed in 'outs'"
940942
):
941-
DataResolver(dvc, tmp_dir.fs_path, dvc_yaml)
943+
resolver.resolve()
942944

943945
def test_param_reserved_namespace_in_vars(self, tmp_dir, dvc):
944946
"""Test that PARAMS_NAMESPACE is reserved and cannot be used in vars."""

0 commit comments

Comments
 (0)