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

Issue using with_param and Pydantic IO #1234

Open
3 of 7 tasks
alicederyn opened this issue Oct 9, 2024 · 0 comments · May be fixed by #1236
Open
3 of 7 tasks

Issue using with_param and Pydantic IO #1234

alicederyn opened this issue Oct 9, 2024 · 0 comments · May be fixed by #1236
Assignees
Labels
type:bug A general bug

Comments

@alicederyn
Copy link
Collaborator

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:

Bug report

Describe the bug
When using with_param with a function using Pydantic IO, an extra argument is added with a name matching the incidental argument name used by the script-decorated function, not the parameters from the Pydantic Input type.

To Reproduce
Full Hera code to reproduce the bug:

from hera.workflows import Workflow, Input, Output, script, Steps
from hera.shared import global_config

global_config.experimental_features["script_pydantic_io"] = True

class ListOutput(Output):
    values: list[str]

class PrintInput(Input):
    value: str

@script()
def produce_list() -> ListOutput:
    return ListOutput(values=["item1", "item2"])

@script()
def print_value(input: PrintInput) -> None:
    print("Value:", input.value)


with Workflow(name="my-workflow") as w:
    with Steps(name="steps"):
        list_step = produce_list(arguments={})
        print_value(with_param=list_step.get_parameter("values"))

Expected behavior

- arguments:
    parameters:
    - name: value  # This is actually "input"
      value: '{{item}}'

Environment

  • Hera Version: 5.17.1
  • Python Version: 3.11.8
  • Argo Version: N/A

Additional context
This is the same root cause as #861, i.e. the code in _get_params_items_from_source, but can't be worked around by avoiding using alternative names.

def _get_param_items_from_source(source: Callable) -> List[Parameter]:
"""Returns a list (possibly empty) of `Parameter` from the specified `source`.
This infers that each non-keyword, positional, argument of the given source is a parameter that stems from a
fanout. Therefore, each parameter value takes the form of `{{item}}` when there's a single argument or
`{{item.<argument name>}}` when there are other arguments.
Returns:
-------
List[Parameter]
A list of identified parameters (possibly empty).
"""
source_signature: List[str] = []
for p in inspect.signature(source).parameters.values():
if p.default == inspect.Parameter.empty and p.kind == inspect.Parameter.POSITIONAL_OR_KEYWORD:
# only add positional or keyword arguments that are not set to a default value
# as the default value ones are captured by the automatically generated `Parameter` fields for positional
# kwargs. Otherwise, we assume that the user sets the value of the parameter via the `with_param` field
source_signature.append(p.name)
if len(source_signature) == 1:
return [Parameter(name=n, value="{{item}}") for n in source_signature]
return [Parameter(name=n, value=f"{{{{item.{n}}}}}") for n in source_signature]

@alicederyn alicederyn added the type:bug A general bug label Oct 9, 2024
@alicederyn alicederyn self-assigned this Oct 9, 2024
alicederyn added a commit to alicederyn/hera that referenced this issue Oct 10, 2024
Add examples reproducing issues argoproj-labs#861 (using with_param with an annotated
input) and argoproj-labs#1234 (using with_param with a Pydantic Input type).

Signed-off-by: Alice Purcell <[email protected]>
@alicederyn alicederyn linked a pull request Oct 10, 2024 that will close this issue
4 tasks
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

Successfully merging a pull request may close this issue.

1 participant