Rob Douglas

01/13/2023, 4:03 PM
hey all, I am trying to understand the intended use of `any_successful`: I have a task I want to run when any upstream task succeeds, and to then get the value from it to use. It's not clear to me, though, how to go about finding which
succeeded. Am I on the right track? I've been poking around for a tutorial or example, but am having trouble finding much in the way of examples of
Copy code
def bar(upstream_tasks):
    # get the first upstream_task that succeeded
gratitude thank you in advance for any insights you might have


01/13/2023, 8:15 PM
hey @Rob Douglas
may be helpful for this
Copy code
from prefect import Flow, task
from prefect.tasks.control_flow.filter import FilterTask

only_successful = FilterTask(lambda x: not isinstance(x, Exception)) # this exact type check may not be appropriate for you

def add_42(x):
    return x + 42

def log(x):

with Flow("any_successful") as flow:
    parameters = ["lemur", dict, "capybara", 42]
    # if you're not mapping, you would construct a list of relevant tasks that may fail
    results = # results = [TypeError, TypeError, TypeError, 84]
    log(only_successful(results)) # prints: [84]
if __name__ == "__main__":

Rob Douglas

01/13/2023, 8:54 PM
Thanks for the insights! There's a couple ideas in there I can check out