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

Script template doesn't work with simple with_items list #1314

Open
3 of 7 tasks
elliotgunton opened this issue Feb 18, 2025 · 0 comments
Open
3 of 7 tasks

Script template doesn't work with simple with_items list #1314

elliotgunton opened this issue Feb 18, 2025 · 0 comments
Labels
type:bug A general bug

Comments

@elliotgunton
Copy link
Collaborator

elliotgunton commented Feb 18, 2025

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. I have searched for existing issues

  • Yes

3. This bug occurs in Hera when...

  • exporting to YAML
  • submitting to Argo
  • running on Argo with the Hera runner
  • other: during the run to build the Hera workflow

Bug report

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

  • Convert the loops example to use a script function
  • Hera will fail to create the workflow (so cannot even output to yaml)

Error log if applicable:

Traceback (most recent call last):
  File "/my-project/examples/bugged_with_items.py", line 9, in <module>
    print_message(
    ~~~~~~~~~~~~~^
        name="print-message-loop",
        ^^^^^^^^^^^^^^^^^^^^^^^^^^
        arguments={"message": "{{item}}"},
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        with_items=["hello world", "goodbye world"],
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/my-project/.venv/lib/python3.13/site-packages/hera/workflows/script.py", line 722, in task_wrapper
    return s.__call__(*args, **kwargs)
           ~~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "/my-project/.venv/lib/python3.13/site-packages/hera/workflows/_meta_mixins.py", line 363, in __call__
    arguments += self._get_deduped_params_from_items(parameter_names, kwargs["with_items"])
                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/my-project/.venv/lib/python3.13/site-packages/hera/workflows/_meta_mixins.py", line 477, in _get_deduped_params_from_items
    item_params = _get_params_from_items(items)
  File "/my-project/.venv/lib/python3.13/site-packages/hera/workflows/_meta_mixins.py", line 330, in _get_params_from_items
    return [Parameter(name=n, value=f"{{{{item.{n}}}}}") for n in with_items[0].keys()]
                                                                  ^^^^^^^^^^^^^^^^^^
AttributeError: 'str' object has no attribute 'keys'

To Reproduce
Full Hera code to reproduce the bug:

from hera.workflows import Container, Parameter, Steps, Workflow, script

@script()
def print_message(message):
    print(message)

with Workflow(generate_name="loops-", entrypoint="loop-example") as w:
    with Steps(name="loop-example"):
        print_message(
            name="print-message-loop",
            arguments={"message": "{{item}}"},
            with_items=["hello world", "goodbye world"],
        )

print(w.to_yaml())

Expected behavior
A clear and concise description of what you expected to happen:

  • Hera prints the valid yaml

Note the script loops maps example works because it is mapping the keys of the function. Here we just want to iterate over the single list of values directly as the {{item}}.

Environment

  • Hera Version: 5.19.0
  • Python Version: 3.13
  • Argo Version: N/A

Additional context
Add any other context about the problem here.

@elliotgunton elliotgunton added the type:bug A general bug label Feb 18, 2025
@elliotgunton elliotgunton changed the title Script template doesn't work with simple with_items Script template doesn't work with simple with_items list Feb 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug A general bug
Projects
None yet
Development

No branches or pull requests

1 participant