<#5353 [BUG] Bug handling Optional type hints unde...
# flytekit
c
#5353 [BUG] Bug handling Optional type hints under conditionals. Issue created by dansola ### Describe the bug The type engine cannot parse
Optional
types when dealing with conditionals using variables coming from dynamic workflows. The
scalar.primitive.string_value
in the example is embedded in a
scalar.union.value
and cannot be found. ### Expected behavior The type engine can handle the
Optional
type under most circumstances, but it should not throw an error in the following example with a dynamic workflow and conditional. ### Additional context to reproduce 1. Run this workflow with
pyflyte --verbose run workflows/optional_wf_2.py optional_wf
from typing import Optional, Tuple from flytekit import dynamic, conditional, task from flytekit import workflow @dynamic def get_str(i: int) -> Tuple[int, Optional[str]]: my_str = None if i > 0: my_str = "test" return i + 2, my_str @task def return_something(my_str: str) -> str: return my_str @task def dont_return_something() -> Optional[str]: return None @workflow def optional_wf(): i = 1 j, my_str = get_str(i=i) ( conditional("check_str") .if_(j > 0) .then(return_something(my_str=my_str)) .else_() .then(dont_return_something()) ) if name == "__main__": optional_wf() 1. Observe the following error:
Copy code
Traceback (most recent call last) 
/lib/python3.11/site-packages/flytekit/core/type_engine.py:250 in to_python_value
❱  250 res = self._from_literal_transformer(lv) 
/lib/python3.11/site-packages/flytekit/core/type_engine.py:1970 in <lambda>                                                                                                                                                                                                                                                                                                                                                  
❱ 1970 lambda x: x.scalar.primitive.string_value,                                                                                                                                           
AttributeError: 'NoneType' object has no attribute 'string_value'
### Screenshots No response ### Are you sure this issue hasn't been raised already? • Yes ### Have you read the Code of Conduct? • Yes flyteorg/flyte