Hi all, Is there any reason why a task runs regard...
# ask-community
d
Hi all, Is there any reason why a task runs regardless of the case result? I want to run a task only when a parameter is set to True. Implemented this using the Case control flow, but it runs irrespective of the case result. That is even when the parameter is set to False.
k
Can you show me a code sample?
d
Copy code
param_flow_compute_bot_markers_enabled = Parameter(
        "Run Compute Bots Markers", default=True
    )

    with case(param_flow_compute_bot_markers_enabled, True):
        <http://logger.info|logger.info>(f"The flow {flow.name} is enabled")
        registered_bots = _utils.get_configured_bots()
I want to execute certain statements only when param_flow_compute_bot_markers_enabled is True
🙌 1
k
This looks right. Maybe you can register and show the schematic?
d
Sure. if not ‘case’ is there any alternative for conditional execution in prefect?
k
No it’s only
case
d
Copy code
with case(param_flow_compute_bot_markers_enabled, False):
        <http://logger.info|logger.info>(f"The flow {flow.name} is disabled. Skipping flow")

    with case(param_flow_compute_bot_markers_enabled, True):
        <http://logger.info|logger.info>(f"The flow {flow.name} is enabled")
I could see both the the log messages with the above example.
k
That’s because the logger is evaluated during Flow creation time. It’s not deferred because it’s not in a task