hera icon indicating copy to clipboard operation
hera copied to clipboard

Task function parameters with defaults are incorrectly marked as required

Open JacobHayes opened this issue 1 year ago • 0 comments

When a task function has a parameter with a default value, the default value doesn't seem to be passed when submitting the workflow, resulting in an HTTP error. The parameter does seem correct in Task.argo_parameters and Task.argo_arguments however.

For example, this workflow:

from typing import Optional

from hera import Task, Workflow, set_global_host, set_global_token

set_global_host(...)
set_global_token(...)


def not_null_default(x: int = 5):
    return x


with Workflow('debug-not-null-default') as workflow:
    task = Task(
        'not-null-default',
        not_null_default,
        image='python',
    )
    print(task.argo_parameters)
    print(task.argo_arguments)
workflow.create()

results in:

Parameters: [{'default': '5', 'name': 'x'}]
Arguments: {'artifacts': [], 'parameters': [{'default': '5', 'name': 'x'}]}
Traceback (most recent call last):
  File "debug_hera_default.py", line 26, in <module>
    workflow.create()
[...]
    raise ServiceException(http_resp=r)
argo_workflows.exceptions.ServiceException: (500)
Reason: Internal Server Error
HTTP response headers: HTTPHeaderDict({'Content-Type': 'application/json', 'Date': 'Mon, 25 Jul 2022 21:41:09 GMT', 'Via': '1.1 google', 'Transfer-Encoding': 'chunked', 'Alt-Svc': 'h3=":443"; ma=2592000,h3-29=":443"; ma=2592000'})
HTTP response body: {"code":2,"message":"templates.debug-not-null-default.tasks.not-null-default.arguments.x.value is required"}

--

As an additional test case, this one should also work (just checks that we handle defaults of None):

def null_default(x: Optional[int] = None):
    return x


with Workflow('debug-null-default') as workflow:
    Task(
        'null-default',
        null_default,
        image='python',
    )
workflow.create()

JacobHayes avatar Jul 25 '22 21:07 JacobHayes