Hi everybody!
I was just wondering why my task not running in the correct order when I'm using
case
.
🙌 2
Gee Xun Chen
05/20/2021, 3:51 AM
Based on the code logic below,
condition
task should be executed first. However, the
case
task executed first although it depends on the
condition
task
Copy code
from prefect import Flow, Parameter, case, task
@task
def condition(table_path):
return table_path
@task
def run_if_cond_is_false():
print("a")
with Flow("example") as flow:
table_path = Parameter("table_path", default="customer_services/freshdesk/ticket/")
cond = condition(table_path)
with case(not cond, False):
run_if_cond_is_false()
Gee Xun Chen
05/20/2021, 3:54 AM
But if I shift the
not
logic into the
condition
task, it works as expected (condition --> case --> run_if_cond_is_false)
Gee Xun Chen
05/20/2021, 3:55 AM
c
Chris White
05/20/2021, 4:04 AM
Hi Gee! I understand your confusion here — Prefect Tasks do not currently support all boolean operations; in this case,
not Task
evaluates immediately to
False
(instead of creating a dependency as you expect), hence the odd execution order you are observing.
To better see this for yourself, you can call
flow.visualize()
in both instances to see the dependency structure that Prefect detected — in your first case you will see two independent graphs with no dependency between them and in the second you will see the structure you are expecting.
The native Python operations that Prefect does and does not support could be better documented, so apologies for the confusion!
Chris White
05/20/2021, 4:05 AM
@Marvin open “Document which Python built-ins Prefect tasks do and do not support”
Bring your towel and join one of the fastest growing data communities. Welcome to our second-generation open source orchestration platform, a completely rethought approach to dataflow automation.