Hi everybody! I was just wondering why my task not...
# ask-community
g
Hi everybody! I was just wondering why my task not running in the correct order when I'm using
case
.
🙌 2
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()
But if I shift the
not
logic into the
condition
task, it works as expected (condition --> case --> run_if_cond_is_false)
c
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!
@Marvin open “Document which Python built-ins Prefect tasks do and do not support”
g
Ok Thanks! 😊
👍 1