Skip to content

Commit

Permalink
Move test for keys starting with _ to the top
Browse files Browse the repository at this point in the history
Signed-off-by: Ankita Katiyar <ankitakatiyar2401@gmail.com>
  • Loading branch information
ankatiyar committed Aug 21, 2023
1 parent 4b1b6f4 commit 01af470
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions kedro/config/omegaconf_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,10 @@ def _register_globals_resolver(self):

def _get_globals_value(self, variable, default_value):
"""Return the globals values to the resolver"""
if variable.startswith("_"):
raise InterpolationResolutionError(
"Keys starting with '_' are not supported for globals."
)
keys = variable.split(".")
value = self["globals"]
for k in keys:
Expand All @@ -334,8 +338,6 @@ def _get_globals_value(self, variable, default_value):
)
return default_value
msg = f"Globals key '{variable}' not found and no default value provided. "
if variable.startswith("_"):
msg += "Keys starting with '_' are not supported for globals."
raise InterpolationResolutionError(msg)
return value

Expand Down
2 changes: 1 addition & 1 deletion tests/config/test_omegaconf_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,6 @@ def test_bad_globals_underscore(self, tmp_path):
conf = OmegaConfigLoader(tmp_path, default_run_env="")
with pytest.raises(
InterpolationResolutionError,
match=r"Globals key '_ignore' not found and no default value provided. Keys starting with '_' are not supported for globals.",
match=r"Keys starting with '_' are not supported for globals.",
):
conf["parameters"]["param2"]

0 comments on commit 01af470

Please sign in to comment.