<@U06RKAMK0UC> provide a simple conditional based ...
# ask-ai
a
@ancient-wolf-19325 provide a simple conditional based task workflow that means i have a, b, c, d, e tasks in workflow I want to execute c task if i provide input as some string if i provide None as input it shouldn't run
j
You can implement this in Flyte using the
conditional
construct. Define tasks a, b, c, d, e, and use a conditional in your workflow to execute c only if the input string is not None; otherwise, skip c. Note that Flyte requires both if and else branches in conditionals, so you can use an "echo" or noop task in the else branch to effectively skip execution (Flyte conditionals guide, noop/echo pattern). Here is a minimal example:
Copy code
import flytekit as fl
from flytekit.core.task import Echo

echo = Echo(name="echo", inputs={"x": str})

@fl.task
def a(): ...
@fl.task
def b(): ...
@fl.task
def c(x: str): ...
@fl.task
def d(): ...
@fl.task
def e(): ...

@fl.workflow
def wf(x: str = None):
    a()
    b()
    conditional_result = (
        fl.conditional("run_c")
        .if_(x.is_not_none())
        .then(c(x=x))
        .else_()
        .then(echo(x=x))
    )
    d()
    e()
Would you like a step-by-step explanation or more details? Sources: - Flyte conditionals guide - noop/echo pattern šŸ‘ 0 button šŸ‘Ž 0 button šŸ’” Hint: Mention @runllm in the thread for followups.
a
│ │ │ 57 │ b() │ │ 58 │ conditional_result = ( │ │ 59 │ │ fl.conditional("run_c") │ │ ā± 60 │ │ .if_(x.is_not_none()) │ │ 61 │ │ .then(c(x=x)) │ │ 62 │ │ .else_() │ │ 63 │ │ .then(echo(x=x)) │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯ TypeError: 'Promise' object is not callable getting this error @ancient-wolf-19325
I am getting this error │ │ │ 57 │ b() │ │ 58 │ conditional_result = ( │ │ 59 │ │ fl.conditional("run_c") │ │ ā± 60 │ │ .if_(x.is_not_none()) │ │ 61 │ │ .then(c(x=x)) │ │ 62 │ │ .else_() │ │ 63 │ │ .then(echo(x=x)) │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯ TypeError: 'Promise' object is not callable getting this error @ancient-wolf-19325
j
Sorry, there was a temporary error when processing your request. Please try again. If this problem persists, please contact support. šŸ‘ 0 button šŸ‘Ž 1 button šŸ’” Hint: Mention @ancient-wolf-19325 in the thread for followups.