Hi Flyte community, does anyone know how to use co...
# flyte-support
h
Hi Flyte community, does anyone know how to use conditionals within an imperative workflow?
a
Can you provide an example of what you'd like to achieve? The docs should cover what can be done, but I have also struggled w/ conditionals in the past - https://docs.flyte.org/en/latest/user_guide/advanced_composition/conditionals.html
h
just implement a simple condition in an imperative workflow the method create_conditional seems to be buggy also the then methods of ConditionalSection expects a Promise which is somewhat tricky when you have the tasks used in the then method return None I think I understand flytes’ internals quite well and I can’t see how anyone could have used this functionality
just note that adding a task in imperative workflow wf.add_task(task=my_task, **my args) returns a node rather than a Promise
t
conditionals aren't supported in imperative workflows.
h
I think I’ve found a way to do it
Copy code
wf_ctx_builder = FlyteContext.current_context().with_compilation_state(wf.compilation_state)
        with FlyteContextManager.with_context(b=wf_ctx_builder):
            some_task = some_task(*args1)
            cond = (
                conditional("conditional_execution")
                .if_(some_task.is_true())
                .then(other_task(*args2))
                .else_()
                .then(third_task(*args3)
            )
other_task and third_task are to be defined using add_task or within the context
It works in fast mode, still need to check it in development