Thread
#prefect-community
    i

    itay livni

    2 years ago
    Hi - Is there a way to
    pass
    on a if else branch?
    Jeremiah

    Jeremiah

    2 years ago
    Hi @itay livni, could you give a little more detail on what you want your workflow to do when that
    pass
    happens? You can absolutely make a task that does nothing but
    pass
    , in which case it will return a
    Success
    state to any downstream tasks containing no result.
    i

    itay livni

    2 years ago
    something like this...
    Jeremiah

    Jeremiah

    2 years ago
    I think I see — you’ll need to change how you write code in Prefect. The code you’ve written is as if your task results are known (for example
    x_lst.value_count().max()
    ). In Prefect, task results are not known until the flow is run, and consequently all operations — including things like
    some_str is "short"
    — must happen inside the
    run()
    method of a
    Task
    object.
    So with
    ifelse
    , you’re saying “if the first task evaluates
    True
    , run the second task; otherwise run the third task”:
    ifelse(conditional_task, true_task, false_task)
    Then you can follow that with new task dependencies:
    another_task_on_true_branch.set_upstream(true_task)
    another_task_on_false_branch.set_upstream(false_task)
    And the ifelse will skip all the tasks that don’t get run
    i

    itay livni

    2 years ago
    so the test statement i.e
    termsense_stat_response["min_num_term_senses"]>1
    has to be a task? Here is an implementation of what I am trying to do in an aws state machine
    sorry wrong one
    Jeremiah

    Jeremiah

    2 years ago
    Yes, every operation in Prefect must be a
    Task
    . In this case, you could use an
    ifelse
    to run
    task1
    if the condition is true, or
    task2
    if the condition is false. You could also call
    task2.set_upstream(task1)
    . This way task 2 will always run, but task 1 will only run if the condition is met.