Parameters and Case statements are appearing to be...
# ask-community
s
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?
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
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
And this is why in Orion you can use the native Python if also (and there is also type checking).
s
gotcha - so basically if I want the task to run for ANY non-false parameter value, I’ll need the helper. Waiting for Orion!!
k
Yes I think that’s right