Skip to content

Commit

Permalink
[serve][cli] Handle nested = in serve run arguments (ray-project#…
Browse files Browse the repository at this point in the history
…49719)

Probably not perfect, but a small patch fix...

Without this:
```
> serve run main:app FOO='abc=def'
Error: Invalid key-value string 'FOO=abc=def'. Must be of the form 'key=value'
```

---------

Signed-off-by: Edward Oakes <ed.nmi.oakes@gmail.com>
Signed-off-by: Puyuan Yao <williamyao034@gmail.com>
  • Loading branch information
edoakes authored and anyadontfly committed Feb 13, 2025
1 parent 2105c0a commit 4bf066e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions python/ray/serve/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ def process_dict_for_yaml_dump(data):
def convert_args_to_dict(args: Tuple[str]) -> Dict[str, str]:
args_dict = dict()
for arg in args:
split = arg.split("=")
if len(split) != 2:
split = arg.split("=", maxsplit=1)
if len(split) != 2 or len(split[1]) == 0:
raise click.ClickException(
f"Invalid application argument '{arg}', "
"must be of the form '<key>=<val>'."
Expand Down
8 changes: 7 additions & 1 deletion python/ray/serve/tests/unit/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,15 @@ def test_convert_args_to_dict():
):
convert_args_to_dict(("bad_arg",))

assert convert_args_to_dict(("key1=val1", "key2=val2")) == {
with pytest.raises(
click.ClickException, match="Invalid application argument 'bad_arg='"
):
convert_args_to_dict(("bad_arg=",))

assert convert_args_to_dict(("key1=val1", "key2=val2", "key3=nested=val")) == {
"key1": "val1",
"key2": "val2",
"key3": "nested=val",
}


Expand Down

0 comments on commit 4bf066e

Please sign in to comment.