https://prefect.io logo
#prefect-community
Title
# prefect-community
p

Philip MacMenamin

08/12/2022, 4:13 PM
If I have a flow, with a task
task_name
, which returns "some_value", and I do:
state = flow.run()
How to I get the return of
task_name
? (ie "some_value")
1
a

Anna Geller

08/12/2022, 4:35 PM
I think it's sth like this:
Copy code
>>> state = flow.run()
>>> state._result.value  # a Flow State's Result value is its Tasks' States
{<Task: add>: <Success: "Task run succeeded.">,
 <Task: add>: <Success: "Task run succeeded.">}
>>> state.result  # the public property aliases the same API as above
{<Task: add>: <Success: "Task run succeeded.">,
 <Task: add>: <Success: "Task run succeeded.">}
>>> state.result[task_ref]._result  # a Task State's Result contains the Task's return value
but if you ask me, this is a bit clunky 😄 I think it's much easier to troubleshoot if you log the info you need while running the flow, or even use a debugger and check the state of any object in between
p

Philip MacMenamin

08/12/2022, 4:38 PM
right, I saw that kind of syntax. I was hoping this wasn't required. I want to just have some asserts in my tests. How could I specifically lookup the
_result
of task
task_name
I guess?
or maybe more clearly: in the above you have:
state.result[task_ref]
where are you getting
task_ref
from?
state.result is a dict of tasks, I'd like to just be able to look up one, but I'm not sure how to do that.
a

Anna Geller

08/12/2022, 5:53 PM
as I said, I think it's much easier to troubleshoot if you log the info you need while running the flow, or even use a debugger and check the state of any object in between
3 Views