Parameters and Case statements are appearing to be less intuitive than I had thought…I can’t figure out a simple way to do something like the following:
Copy code
val = Parameter("param", False):
case(val, True):
do_stuff()
case(val, False):
dont_do_stuff()
If my paramter is an actual value, i.e. “value”, it skips both because it’s neither True nor False. So I’m left to make another task to check the value. Is this correct?
Sam Werbalowsky
01/03/2022, 10:28 PM
Logs just show this
Copy code
[2022-01-03 17:21:27-0500] INFO - prefect.TaskRunner | SKIP signal raised: SKIP('Provided value "VALUE" did not match "False"')
[2022-01-03 17:21:27-0500] INFO - prefect.TaskRunner | Task 'case(True)': Starting task run...
[2022-01-03 17:21:27-0500] INFO - prefect.TaskRunner | Task 'case(False)': Finished task run for task with final state: 'Skipped'
[2022-01-03 17:21:27-0500] INFO - prefect.TaskRunner | SKIP signal raised: SKIP('Provided value "VALUE" did not match "True"')
k
Kevin Kho
01/03/2022, 10:35 PM
I think that is right, except for the fact that the second input of
case
is not limited to True or False. It can be a constant number for example:
Copy code
from prefect import Flow, task, case, Parameter
import prefect
@task
def do_something():
<http://prefect.context.logger.info|prefect.context.logger.info>("this ran")
return 1
with Flow("conditional-branches") as flow:
cond = Parameter("cond", 3)
with case(cond, 3):
val = do_something()
flow.run()
upvote 1
Kevin Kho
01/03/2022, 10:35 PM
And this is why in Orion you can use the native Python if also (and there is also type checking).
s
Sam Werbalowsky
01/03/2022, 10:38 PM
gotcha - so basically if I want the task to run for ANY non-false parameter value, I’ll need the helper. Waiting for Orion!!
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.