https://prefect.io logo
Title
j

Jake Schmidt

12/18/2019, 10:51 PM
How do I access the
result
of a given task in a flow? I see that
flow.run().result
is a
dict
keyed by `Task`s but
flow.run().result[prefect.Task('task_name')]
gives a
KeyError
. I can’t find the answer in the documentation or the api reference for
State
.
j

Jeremiah

12/18/2019, 10:51 PM
Jake, access the
result
attribute by the task itself:
flow.run().result[your_task].result
flow.run()
returns a
State
for the flow, and that state has a result dict. Each value of the result dict is the final
State
of the corresponding task key, and each of those states has its own stored result
j

Jackson Maxfield Brown

12/18/2019, 10:52 PM
I had a similar question but we have been using this for a while. @Jeremiah does this seem correct?
# Run the flow
state = flow.run(executor=executor)

# Get resulting path
save_path = state.result[flow.get_tasks(name="_get_save_path")[0]].result
j

Jeremiah

12/18/2019, 10:53 PM
👍 absolutely — and to apply to @Jake Schmidt’s situation, if you don’t have the task object handy then
flow.get_tasks(name=X)[0]
will return it for you
j

Jake Schmidt

12/18/2019, 10:57 PM
Works, thanks!
👍 1