-
Notifications
You must be signed in to change notification settings - Fork 117
Closed
Labels
type:bugA general bugA general bug
Description
Pre-bug-report checklist
1. This bug can be reproduced using YAML
- Yes 👉 Please report a bug to the Argo Workflows GitHub 👈
- No
The bug is related to the script runner and has a workaround that we can implement. Will be submitting an issue upstream soon.
2. This bug occurs when...
- running Hera code without submitting to Argo (e.g. when exporting to YAML)
- running Hera code and submitting to Argo
Bug report
Describe the bug
A clear and concise description of what the bug is:
Use a "runner script" constructor, and make the script an inline template using the workaround in #628:
@script(constructor="runner")
def print_message(message: str):
print(message)
with Workflow(
name="hera-inline-test",
entrypoint="d",
) as w:
with DAG(name="d"):
task = print_message(arguments={"message": "test"})
task.inline = w.templates.pop()
task.template = NoneYou can then see in the templates generated yaml:
templates:
- dag:
tasks:
- arguments:
parameters:
- name: message
value: test
inline:
inputs:
parameters:
- name: message
name: print-message
script:
args:
- -m
- hera.workflows.runner
- -e
- herainlinetest.workflow_template:print_message
command:
- python
image: # <private image>
source: '{{inputs.parameters}}'
name: print-message
name: dThe line source: '{{inputs.parameters}}' is actually referring to the dag's {{inputs.parameters}} which doesn't exist, so when submitted, the task errors out with a pydantic error as the parameters aren't present.
We can work around this by constructing the list of parameters via the names themselves, e.g. using a custom script constructor:
class InlineTemplateRunnerScriptConstructor(RunnerScriptConstructor):
"""A workaround constructor to allow our runner script to be an inline template."""
def generate_source(self, instance: Script) -> str:
"""Convert inputs to a json string containing a list of dicts.
Each dict contains the keys "name" and "value" with corresponding values
for each input parameter in `instance`.
"""
inputs = instance._build_inputs()
if inputs is None or not inputs.parameters:
return ""
input_params = []
for param in inputs.parameters:
input_params.append(
{"name": param.name, "value": f"{{{{inputs.parameters.{param.name}}}}}"}
)
return json.dumps(input_params)Metadata
Metadata
Assignees
Labels
type:bugA general bugA general bug