Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Bug handling Optional type hints under conditionals. #5353

Open
2 tasks done
dansola opened this issue May 10, 2024 · 0 comments
Open
2 tasks done

[BUG] Bug handling Optional type hints under conditionals. #5353

dansola opened this issue May 10, 2024 · 0 comments
Labels
backlogged For internal use. Reserved for contributor team workflow. bug Something isn't working flytekit FlyteKit Python related issue

Comments

@dansola
Copy link
Contributor

dansola commented May 10, 2024

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:
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
@dansola dansola added bug Something isn't working untriaged This issues has not yet been looked at by the Maintainers labels May 10, 2024
@eapolinario eapolinario added flytekit FlyteKit Python related issue backlogged For internal use. Reserved for contributor team workflow. and removed untriaged This issues has not yet been looked at by the Maintainers labels May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backlogged For internal use. Reserved for contributor team workflow. bug Something isn't working flytekit FlyteKit Python related issue
Projects
None yet
Development

No branches or pull requests

2 participants