How do I access the `result` of a given task in a ...
# prefect-community
j
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
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
I had a similar question but we have been using this for a while. @Jeremiah does this seem correct?
Copy code
# 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
👍 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
Works, thanks!
👍 1