Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify _split_params to handle a list #4205

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
* Moved pattern resolution logic from `DataCatalog` to a separate component - `CatalogConfigResolver`. Updated `DataCatalog` to use `CatalogConfigResolver` internally.
* Made packaged Kedro projects return `session.run()` output to be used when running it in the interactive environment.
* Enhanced `OmegaConfigLoader` configuration validation to detect duplicate keys at all parameter levels, ensuring comprehensive nested key checking.

## Bug fixes and other changes
* Fixed bug where using dataset factories breaks with `ThreadRunner`.
* Fixed a bug where `SharedMemoryDataset.exists` would not call the underlying `MemoryDataset`.
* Fixed template projects example tests.
* Made credentials loading consistent between `KedroContext._get_catalog()` and `resolve_patterns` so that both us
e `_get_config_credentials()`
* Made credentials loading consistent between `KedroContext._get_catalog()` and `resolve_patterns` so that both use `_get_config_credentials()`
* Allow runtime parameters to be wrapped in a list.

## Breaking changes to the API
* Removed `ShelveStore` to address a security vulnerability.
Expand Down
12 changes: 12 additions & 0 deletions kedro/framework/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

import ast
import difflib
import importlib
import logging
Expand Down Expand Up @@ -471,6 +472,17 @@ def _validate_config_file(key: str) -> None:
def _split_params(ctx: click.Context, param: Any, value: Any) -> Any:
if isinstance(value, dict):
return value
if isinstance(value, list) and len(value) == 1:
value = value[0]
# Try evaluating the string as a Python literal in case it contains a list
if isinstance(value, str):
try:
evaluated_value = ast.literal_eval(value)
if isinstance(evaluated_value, list) and len(evaluated_value) == 1:
value = evaluated_value[0]
except (ValueError, SyntaxError):
pass # Safely continue if the evaluation fails

dot_list = []
for item in split_string(ctx, param, value):
equals_idx = item.find("=")
Expand Down
2 changes: 2 additions & 0 deletions tests/framework/cli/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,8 @@ def test_run_with_params_in_config(
"foo.nested_1.double_nest=123.45,foo.nested_2=1a",
{"foo": {"nested_1": {"double_nest": 123.45}, "nested_2": "1a"}},
),
(["foo=bar,fizz=buzz"], {"foo": "bar", "fizz": "buzz"}),
('["foo=bar,fizz=buzz"]', {"foo": "bar", "fizz": "buzz"}),
],
)
def test_run_extra_params(
Expand Down