Hi all. I have a state_handler for flow where I’m ...
# ask-community
n
Hi all. I have a state_handler for flow where I’m trying to extract information about which of the tasks failed (
new_state.result
) and error details. But it’s empty and I can get only “Some reference tasks failed.” from
new_state
. Is it possible to extract this kind of details?
k
Hey @nib, we don’t store all results because it could be a very large piece of data. There is something new in 0.15.0 that addresses this. You can do something like this in the handler:
Copy code
from prefect import task
from prefect.backend import TaskRunView

# Presume we have a flow with the following task
@task
def foo():
  return "foobar!"

# Instantiate a task run directly
task_run = TaskRunView.from_task_slug("foo-1", flow_run_id="")

# As with the other views, we can inspect the task run
task_run.state      # Success(...)
task_run.map_index  # -1  (not mapped)

# We can also retrieve results
task_run.get_result()  # "foobar!"
You can get flow run id from the context
n
Thank you, @Kevin Kho
r
@Kevin Kho what if the flow was: foo->foo->foo How to identify on which foo task run was the state handler called?
k
@Ranu Goldan, I think you can get it from the context task slug and there will be a number there.