<@ULVA73B9P> why True Task is always run even if c...
# marvin-in-the-wild
s
@Marvin why True Task is always run even if condition is False
Copy code
with Flow("flow") as flow:
    value = Constant(value="This is True Task", name='Generate constant')()
    condition = FunctionTask(fn=lambda: False, name='Always False Condition')()
    with case(condition, True):
        final_value = merge(value)
        FunctionTask(fn=lambda v: prefect.context.get('logger').info(v), name='True Task')(final_value)
    with case(condition, False):
        FunctionTask(lambda: prefect.context.get('logger').info('This is False Task'), name='False Task')()
m
I've looked into the matter, and none of the search results from the Prefect documentation directly address why a task within a
with case(...)
block would run even if the condition is false. The search results seem irrelevant to the specific issue at hand, so I'll need to use another strategy. Let's look for similar issues in the Prefect GitHub repository to see if there has been any discussion of this behavior. I will search for any related GitHub issues now. One moment, please. It appears there are no GitHub issues that directly address the problem you're experiencing with tasks running regardless of the condition in the
case
block. Since we haven't found an existing solution, let's consider how the
case
statement is supposed to function within Prefect workflows. The
case
block is intended to enforce conditional logic based on the value of the preceding condition. If the condition is
False
, then only the tasks inside the
with case(condition, False):
block should execute. I suggest re-examining your flow definition to ensure it conforms to Prefect's expected behavior and reviewing Prefect's documentation on ControlFlow. It might also be helpful to double-check that there are no unintended references or dependencies outside of the
case
block that could cause the task within the
True
case to execute despite the condition's value. If this issue persists and you strongly believe this behavior isn't consistent with the documentation, it might be beneficial to open a new issue on the Prefect GitHub repository to get assistance from the developers.