Hi all - wondering if having multiple optional inp...
# ask-the-community
h
Hi all - wondering if having multiple optional inputs for tasks (with defaults provided) is supported? Will drop a minimal example in 🧵, but essentially we have tasks with one default provided that serialize just fine but tasks with more than one default provided that don't serialize, with the error
flytekit.exceptions.user.FlyteAssertion: Input was not specified for: optional_int of type simple: INTEGER
. Issues #1312 [BUG][flytekit] Default input argument not being considered in PythonInstanceTask and #3046 both seem related. Has anyone else seen this before? (flytekit 1.3.0)
cc @Ailin Yu
Here's a minimal example that fails to compile:
Copy code
from flytekit import task, workflow

_OPTIONAL_INT = 5
_OPTIONAL_STR_1 = "foo"
_OPTIONAL_STR_2 = "bar"


@task
def one_default_task(
    required_input: str,
    optional_int: int = _OPTIONAL_INT,
) -> str:
    return required_input + str(optional_int)


@task
def lots_of_defaults_task(
    required_input: str,
    optional_int: int = _OPTIONAL_INT,
    optional_str_1: str = _OPTIONAL_STR_1,
    optional_str_2: str = _OPTIONAL_STR_2,
) -> str:
    return required_input + str(optional_int) + optional_str_1 + optional_str_2


@task
def no_defaults_task(
    string1: str,
    string2: str,
) -> str:
    return string1 + string2


@workflow
def some_fussy_defaults_workflow(required_input: str) -> str:
    output1 = one_default_task(required_input=required_input)
    output2 = lots_of_defaults_task(required_input=required_input)
    return no_defaults_task(output1, output2)
And here's the full serialization error:
Copy code
Traceback (most recent call last):
  File "/root/micromamba/envs/sci-ops-dev/lib/python3.8/site-packages/flytekit/exceptions/scopes.py", line 160, in system_entry_point
    return wrapped(*args, **kwargs)
  File "/root/micromamba/envs/sci-ops-dev/lib/python3.8/site-packages/flytekit/clis/sdk_in_container/serialize.py", line 69, in serialize_all
    serialize_to_folder(pkgs, serialization_settings, local_source_root, folder)
  File "/root/micromamba/envs/sci-ops-dev/lib/python3.8/site-packages/flytekit/tools/repo.py", line 63, in serialize_to_folder
    loaded_entities = serialize(pkgs, settings, local_source_root, options=options)
  File "/root/micromamba/envs/sci-ops-dev/lib/python3.8/site-packages/flytekit/tools/repo.py", line 46, in serialize
    module_loader.just_load_modules(pkgs=pkgs)
  File "/root/micromamba/envs/sci-ops-dev/lib/python3.8/site-packages/flytekit/tools/module_loader.py", line 33, in just_load_modules
    importlib.import_module(name)
  File "/root/micromamba/envs/sci-ops-dev/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 843, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/src/flyte/sci_ops/failing_workflow.py", line 35, in <module>
    def some_fussy_defaults_workflow(required_input: str) -> str:
  File "/root/micromamba/envs/sci-ops-dev/lib/python3.8/site-packages/flytekit/core/workflow.py", line 764, in workflow
    return wrapper(_workflow_function)
  File "/root/micromamba/envs/sci-ops-dev/lib/python3.8/site-packages/flytekit/core/workflow.py", line 759, in wrapper
    workflow_instance.compile()
  File "/root/micromamba/envs/sci-ops-dev/lib/python3.8/site-packages/flytekit/core/workflow.py", line 636, in compile
    workflow_outputs = exception_scopes.user_entry_point(self._workflow_function)(**input_kwargs)
  File "/root/micromamba/envs/sci-ops-dev/lib/python3.8/site-packages/flytekit/exceptions/scopes.py", line 207, in user_entry_point
    raise FlyteScopedUserException(*_exc_info())
flytekit.exceptions.scopes.FlyteScopedUserException: Input was not specified for: optional_int of type simple: INTEGER
k
Default inputs are not supported for tasks. Only optional inputs are supported- you can default to none. The compiler should have complained for unbound inputs Reason is there is no easy way to have all values as defaults
Cc @Eduardo Apolinario (eapolinario) / @Niels Bantilan let’s talk about this
157 Views