Hi flyte folks, i think i encountered another Opti...
# ask-the-community
Hi flyte folks, i think i encountered another Optional type related issue. This seem to be happening only during local execution though. Issue: For dynamic tasks with Optional return it crashes if we explicitly return None. Example code:
Copy code
def dyn_optional_str(optional_str: Optional[str]) -> Optional[str]:
    return None

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
Copy code
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
i think it might be some oversight on flytekit side 🤔
if confirmed i can open up an issue ticket btw flytekit version is
maybe its fixed in later versions 🤔
@Jay Ganbat, thanks for the report. Can you file a gh issue? I can confirm that this affects latest (1.7.0) flytekit as well.
thanks for confirming here is the issue https://github.com/flyteorg/flyte/issues/3812