flyteorg / flyte

Scalable and flexible workflow orchestration platform that seamlessly unifies data, ML and analytics stacks.
https://flyte.org
Apache License 2.0
5.81k stars 660 forks source link

[BUG] Flyte conditional must take an else task #5990

Open peterghaddad opened 2 weeks ago

peterghaddad commented 2 weeks ago

Describe the bug

When using Flyte Conditions without an else().then() statement the condition immediately fails. As an end-user, I expect to have the else statement be optional.

Expected behavior

See the code snippet below, but ideally Flyte conditionals will function without an else statement.

Additional context to reproduce

Using this code:

@task
def coin_toss(seed: int) -> bool:
    """
    Mimic a condition to verify the successful execution of an operation
    """
    r = random.Random(seed)
    if r.random() < 0.5:
        return True
    return False

@task
def failed() -> int:
    """
    Mimic a task that handles failure
    """
    return -1

@task
def success() -> int:
    """
    Mimic a task that handles success
    """
    return 0

@workflow
def boolean_wf(seed: int = 5) -> int:
    result = coin_toss(seed=seed)
    return conditional("coin_toss").if_(result.is_true()).then(success())

Screenshots

No response

Are you sure this issue hasn't been raised already?

Have you read the Code of Conduct?

eapolinario commented 1 week ago

@peterghaddad , recently we added a no-op task to be used in these cases (details here). I know it's not ideal, but we're one hop away from possibly detecting this automatically, i.e. we could have flytekit detect the missing else and insert a noop else branch (with the caveat that it'd show up in flyteconsole).

Contributions are welcome! Here's the original flytekit PR that added echo to the SDK: https://github.com/flyteorg/flytekit/pull/2654.