diff --git a/examples/workflows/experimental/pydantic_io_in_dag_context.py b/examples/workflows/experimental/pydantic_io_in_dag_context.py index 8066d4eca..6f1e802f4 100644 --- a/examples/workflows/experimental/pydantic_io_in_dag_context.py +++ b/examples/workflows/experimental/pydantic_io_in_dag_context.py @@ -11,7 +11,7 @@ from hera.workflows import DAG, Parameter, WorkflowTemplate, script from hera.workflows.io.v1 import Input, Output -global_config.experimental_features["script_pydantic_io"] = True +global_config.experimental_features["decorator_syntax"] = True class CutInput(Input): diff --git a/examples/workflows/experimental/pydantic_io_in_steps_context.py b/examples/workflows/experimental/pydantic_io_in_steps_context.py index 2517b20f8..be297b897 100644 --- a/examples/workflows/experimental/pydantic_io_in_steps_context.py +++ b/examples/workflows/experimental/pydantic_io_in_steps_context.py @@ -11,7 +11,7 @@ from hera.workflows import Parameter, Steps, WorkflowTemplate, script from hera.workflows.io.v1 import Input, Output -global_config.experimental_features["script_pydantic_io"] = True +global_config.experimental_features["decorator_syntax"] = True class CutInput(Input): diff --git a/src/hera/workflows/script.py b/src/hera/workflows/script.py index d6394a34a..e62f46c8d 100644 --- a/src/hera/workflows/script.py +++ b/src/hera/workflows/script.py @@ -40,6 +40,7 @@ from hera.expr import g from hera.shared import BaseMixin, global_config from hera.shared._global_config import ( + _DECORATOR_SYNTAX_FLAG, _SCRIPT_ANNOTATIONS_FLAG, _SCRIPT_PYDANTIC_IO_FLAG, _flag_enabled, @@ -378,15 +379,19 @@ def _get_parameters_from_callable(source: Callable) -> List[Parameter]: return parameters +def please_enable_experimental_feature(flag: str) -> str: + return ( + "Please turn on experimental features by setting " + f'`hera.shared.global_config.experimental_features["{flag}"] = True`.' + " Note that experimental features are unstable and subject to breaking changes." + ) + + def _assert_pydantic_io_enabled(annotation: str) -> None: if not _flag_enabled(_SCRIPT_PYDANTIC_IO_FLAG): raise ValueError( - ( - "Unable to instantiate {} since it is an experimental feature." - " Please turn on experimental features by setting " - '`hera.shared.global_config.experimental_features["{}"] = True`.' - " Note that experimental features are unstable and subject to breaking changes." - ).format(annotation, _SCRIPT_PYDANTIC_IO_FLAG) + f"Unable to instantiate {annotation} since it is an experimental feature. " + + please_enable_experimental_feature(_SCRIPT_PYDANTIC_IO_FLAG) ) @@ -767,6 +772,11 @@ def task_wrapper(*args, **kwargs) -> Union[FuncR, Step, Task, None]: """Invokes a `Script` object's `__call__` method using the given SubNode (Step or Task) args/kwargs.""" if _context.active: if len(args) == 1 and isinstance(args[0], (InputV1, InputV2)): + if not _flag_enabled(_DECORATOR_SYNTAX_FLAG): + raise SyntaxError( + "Cannot pass a Pydantic type inside a context. " + + please_enable_experimental_feature(_DECORATOR_SYNTAX_FLAG) + ) arguments = args[0]._get_as_arguments() arguments_list = [ *(arguments.artifacts or []), diff --git a/tests/test_pydantic_io_syntax.py b/tests/test_pydantic_io_workflow_syntax.py similarity index 91% rename from tests/test_pydantic_io_syntax.py rename to tests/test_pydantic_io_workflow_syntax.py index cf9e16735..353a9c2e7 100644 --- a/tests/test_pydantic_io_syntax.py +++ b/tests/test_pydantic_io_workflow_syntax.py @@ -1,6 +1,6 @@ import pytest -from hera.shared._global_config import _SCRIPT_PYDANTIC_IO_FLAG +from hera.shared._global_config import _DECORATOR_SYNTAX_FLAG from hera.workflows import Input, Output, Steps, Workflow, script @@ -14,7 +14,7 @@ class IntOutput(Output): @pytest.fixture(autouse=True) def enable_pydantic_io(global_config_fixture): - global_config_fixture.experimental_features[_SCRIPT_PYDANTIC_IO_FLAG] = True + global_config_fixture.experimental_features[_DECORATOR_SYNTAX_FLAG] = True def test_output_field_contains_argo_template(global_config_fixture):