Hi, quick question, Is it fine to use `if` inside ...
# prefect-community
s
Hi, quick question, Is it fine to use
if
inside flow like this:
Copy code
def flow_func(ip):
    with Flow('flow func') as flow:
        task1()
        if ip == True:
            task2()
e
It is fine, depending on the value of
ip
, your flow will contain or not contain
task2
. This wouldn’t work if you derived the value of
ip
from within a task, for ex.
ip = task1()
. Because tasks aren’t run, therefore their results are unknown, before
flow.run()
is called.
s
There is also an interesting PR (https://github.com/PrefectHQ/prefect/pull/2443) that introduces a new case statement that strengthens the conditional support. That would replace your if and my ifelse.
j
@Sumant Agnihotri that is perfectly fine as long as your goal is to produce a flow that may or may not contain
task2
. If your goal is to always have task2, but only run it sometimes, you’ll need to use a Prefect control-flow statement like the one @Steve Taylor mantioned.
@Steve Taylor - that PR has been merged! You can use it with the current release of Prefect (and it’s really really useful): https://medium.com/the-prefect-blog/prefect-0-11-0-improved-apis-and-targets-79fef9d90aec?postPublishedType=repub
s
@Jeremiah I suspected as much so I started, ahem reading through the release notes... I've already converted on flow already this morning... on the march to production now. I'll send the medium article to my folks. Thanks!
🚀 1
j
Awesome!