I'm confused about `return_state=True` for tasks a...
# best-practices
r
I'm confused about
return_state=True
for tasks and flows. I'm wanting to return the state so that the main flow will not fail if the subflow or task fails. I have a flow with several subflows where I use
return_state=True
and get the data later with
.result()
. This works even if the subflow failed because the result ends up being the failed state (or something like that). But I'm trying to use the same pattern within a task, and as soon as I call
.result()
, the flow fails. Is this the expected behavior? Does
return_state=True
work differently for subflows and tasks?
n
> as soon as I call
.result()
, the flow fails. Is this the expected behavior? yes. because a
Failed
task or flow run would have an
Exception
as its result value, you're "unwrapping" that
Exception
when you call
.result()
the
State
you get back when you say
return_state=True
has methods like
is_failed()
which you can use to conditionally avoid unwrapping exception values if you want to avoid failing the calling flow