https://flyte.org logo
#ask-the-community
Title
# ask-the-community
c

Cornelis Boon

03/11/2024, 2:17 PM
Is there a way to have two conditionals depend on each other? e.g.
Copy code
@workflow
def conditional_dependency_wf(condition1: bool, condition2: bool):
 init_data = get_initial_task()
conditional_promise1 = ( 
        conditional("if-cond1")
        .if_(condition1.is_true())
        .then( task1(data=init_data))
    )
conditional_promise2 = ( 
        conditional("if-cond2")
        .if_(condition2.is_true())
        .then( task2(data=init_data))
    )

conditional_promise1 >> conditional_promise2
Without having to nest them 🙂 I feel this should be possible given these examples: https://docs.flyte.org/en/latest/user_guide/advanced_composition/conditionals.html#using-the-output-of-a-previous-task-in-a-conditional
If I try this though: I get a
unsupported operand type(s) for >>: 'Condition' and 'Condition'
error
Ah, I see it only works if I specify both an
if_
cases and an
else_
. To get around it, I specify a task that just does nothing for the else_ part. something like
Copy code
@task
def _else():
    ...
and the workflow then becomes:
Copy code
@workflow
def conditional_dependency_wf(condition1: bool, condition2: bool):
 init_data = get_initial_task()
conditional_promise1 = ( 
        conditional("if-cond1")
        .if_(condition1.is_true())
        .then( task1(data=init_data)).else_().then(_else())
    )
conditional_promise2 = ( 
        conditional("if-cond2")
        .if_(condition2.is_true())
        .then( task2(data=init_data)).else_().then(_else())
    )

conditional_promise1 >> conditional_promise2
k

Kevin Su

03/11/2024, 6:12 PM
could you file a ticket? we’ll fix that. [flyte-bug]
c

Cornelis Boon

03/11/2024, 6:18 PM
Sure. Another thing is that the graph in the console looks a bit illogical for a workflow above. The
get_initial_task()
is drawn on a parallel path from the condition, even though the "if" branch of the conditional is dependent on the output of the first task. Don't have a screenshot as I'm setting up the cluster again, but it looked like this:
Copy code
start ->               init_task   ->    end
  \-> [startcond] -> if_cond1 [endcond] ->/
           \-> else         ->/
So init_task would be
get_initial_task
and is drawn on a separate path from start to end than the conditional. I would expect the
get_initial_task
to be drawn before the conditional, with two branches in the conditional both pointing to the end.
Here's a screenshot of what I meant about the graph. @Kevin Su I would expect the
download_jpeg
to be in front of or at least have an edge going out to
if_lpr
which is the conditional
https://github.com/flyteorg/flyte/issues/4240 Seems like that is already described in this issue
2 Views