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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Optional/Union types in script runner #1012

Open
2 of 6 tasks
elliotgunton opened this issue Mar 27, 2024 · 0 comments
Open
2 of 6 tasks

Support Optional/Union types in script runner #1012

elliotgunton opened this issue Mar 27, 2024 · 0 comments
Labels
type:bug A general bug type:enhancement A general enhancement

Comments

@elliotgunton
Copy link
Collaborator

elliotgunton commented Mar 27, 2024

Pre-bug-report checklist

1. This bug can be reproduced using pure Argo YAML

If yes, it is more likely to be an Argo bug unrelated to Hera. Please double check before submitting an issue to Hera.

2. This bug occurs in Hera when...

  • exporting to YAML
  • submitting to Argo
  • running on Argo with the Hera runner
  • other:

Bug report

Describe the bug
A clear and concise description of what the bug is:

Using a function with an optional (string, but I think could be any type) argument in the runner results in the following stack trace:

Error log if applicable:

  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/layers/.../requirements/lib/python3.11/site-packages/hera/workflows/runner.py", line 6, in <module>
    _run()
  File "/layers/.../requirements/lib/python3.11/site-packages/hera/workflows/_runner/util.py", line 254, in _run
    result = _runner(args.entrypoint, kwargs_list)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/layers/.../requirements/lib/python3.11/site-packages/hera/workflows/_runner/util.py", line 225, in _runner
    raise e
  File "/layers/.../requirements/lib/python3.11/site-packages/hera/workflows/_runner/util.py", line 222, in _runner
    output = _save_annotated_return_outputs(function(**kwargs), output_annotations)
                                            ^^^^^^^^^^^^^^^^^^
  File "/layers/.../requirements/lib/python3.11/site-packages/hera/workflows/_runner/util.py", line 58, in inner
    filtered_kwargs = {key: _parse(value, key, f) for key, value in kwargs.items() if _is_kwarg_of(key, f)}
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/layers/.../requirements/lib/python3.11/site-packages/hera/workflows/_runner/util.py", line 58, in <dictcomp>
    filtered_kwargs = {key: _parse(value, key, f) for key, value in kwargs.items() if _is_kwarg_of(key, f)}
                            ^^^^^^^^^^^^^^^^^^^^^
  File "/layers/.../requirements/lib/python3.11/site-packages/hera/workflows/_runner/util.py", line 89, in _parse
    if _is_str_kwarg_of(key, f) or _is_artifact_loaded(key, f) or _is_output_kwarg(key, f):
       ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/layers/.../requirements/lib/python3.11/site-packages/hera/workflows/_runner/util.py", line 142, in _is_str_kwarg_of
    return issubclass(type_, str)
           ^^^^^^^^^^^^^^^^^^^^^^
TypeError: issubclass() arg 1 must be a class

To Reproduce
Full Hera code to reproduce the bug:

from hera.workflows import Workflow, script

@script(constructor="runner", image="my-image")
def optional_str(my_str: Optional[str], another_str: str | None):  # note the old/new ways to specify optional
    print(my_str)
    print(another_str)

with Workflow(name="my-workflow", entrypoint="optional-str") as w:
    optional_str()

Expected behavior
A clear and concise description of what you expected to happen:
No error trace.

Environment

  • Hera Version: 5.14.3
  • Python Version: 3.11
  • Argo Version: 3.4.16

Additional context
Add any other context about the problem here.
We can currently work around this by using an empty string as the default.

@script(constructor="runner", image="my-image")
def optional_str(my_str: str = "", another_str: str = ""):
    print(my_str)
    print(another_str)
@elliotgunton elliotgunton added type:bug A general bug type:enhancement A general enhancement labels Mar 27, 2024
@elliotgunton elliotgunton changed the title Support Optional Support Optional types in script runner Mar 27, 2024
@elliotgunton elliotgunton changed the title Support Optional types in script runner Support Optional/Union types in script runner Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug A general bug type:enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

1 participant