Skip to content

Commit

Permalink
Fix edge case for model arguments Parameter conversion
Browse files Browse the repository at this point in the history
Signed-off-by: Elliot Gunton <elliotgunton@gmail.com>
  • Loading branch information
elliotgunton committed Mar 5, 2025
1 parent 3146b43 commit 3cedf3b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/hera/workflows/_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,13 @@ def _build_arguments(self) -> Optional[ModelArguments]:
if normalized_arguments is None:
return None
elif isinstance(normalized_arguments, ModelArguments):
# Special case as Parameter is a subclass of ModelParameter
# We need to convert Parameters to ModelParameters
if normalized_arguments.parameters:
normalized_arguments.parameters = [
ModelParameter.parse_obj(p.dict()) if isinstance(p, Parameter) else p
for p in normalized_arguments.parameters
]
return normalized_arguments

from hera.workflows.workflow_template import WorkflowTemplate
Expand Down
26 changes: 25 additions & 1 deletion tests/test_unit/test_mixins.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from hera.workflows import Env, Parameter
from hera.workflows import Env, Parameter, Workflow
from hera.workflows._mixins import ArgumentsMixin, ContainerMixin, EnvMixin, IOMixin
from hera.workflows.models import (
Arguments as ModelArguments,
Expand Down Expand Up @@ -113,6 +113,30 @@ def test_model_arguments_value_is_not_normalized_to_list(self):
assert args_mixin.arguments == ModelArguments()


def test_build_arguments_of_parameter_converted(self):
args_mixin = ArgumentsMixin(
arguments=[
Parameter(name="my-param-1"),
Parameter(name="my-param-2"),
]
)
built_args = args_mixin._build_arguments()
assert built_args and built_args.parameters == [
ModelParameter(name="my-param-1"),
ModelParameter(name="my-param-2"),
]

def test_build_workflow(self):
with Workflow(
name="test",
arguments=ModelArguments(parameters=[Parameter(name="test", value="value")]),
) as w:
pass

workflow = w.build()
assert workflow.spec.arguments.parameters == [ModelParameter(name="test", value="value")]


class TestEnvMixin:
def test_list_normalized_to_list(self):
env_mixin = EnvMixin(
Expand Down

0 comments on commit 3cedf3b

Please sign in to comment.