<#3812 [BUG] Returning None on dynamic task with O...
# flytekit
c
#3812 [BUG] Returning None on dynamic task with Optional return crashes local execution. Issue created by jganbat-fn ### Describe the bug Issue: For dynamic tasks with Optional return it crashes if we explicitly return None during local execution. Example code:
Copy code
@dynamic
def dyn_optional_str(optional_str: Optional[str]) -> Optional[str]:
    return None

@workflow
def workflow_with_optional_input(optional_str: Optional[str]) -> Optional[str]:
    hello_output = dyn_optional_str(optional_str=optional_str)
    return hello_output
and test was done like this
def test_example() -> None:
    result = workflow_with_optional_input(optional_str=None)
    assert result is None
and it crashes with this error
Copy code
except Exception as e:
                    logger.error(f"Failed to convert return value for var {k} with error {type(e)}: {e}")
>                   raise TypeError(
                        f"Failed to convert return value for var {k} for function {self.name} with error {type(e)}: {e}"
                    ) from e
E                   TypeError: Failed to convert return value for var o0 for function sandbox.dynamic_optional_type.dyn_optional_str with error <class 'AssertionError'>: Task sandbox.dynamic_optional_type.dyn_optional_str returns nothing, NoneType return cannot be used

/fn/lib/venv/lib/python3.10/site-packages/flytekit/core/base_task.py:572: TypeError
### Expected behavior Local execution should finish successfully and return None. ### Additional context to reproduce No response ### Screenshots No response ### Are you sure this issue hasn't been raised already? • Yes ### Have you read the Code of Conduct? • Yes flyteorg/flyte