In order to cancel the rest of the pipeline on err...
# ask-community
m
In order to cancel the rest of the pipeline on error I'm returning
Failed(message=...)
from one of my tasks. I can type-annotate this function to say that it returns either an object or a state, but this seems like more negative engineering in my calling code when in 99% of all cases it returns an object. When calling
.fn()
in my test
return_state
is not available as a parameter, which would inform my type-checker that the result is actually a state. Is there a better way to fail my pipeline, or a better way to perform this assert in my test?
1
Seems like maybe a type-guard is the safest and simplest option:
Copy code
from prefect.server.schemas.states import State

maybe_result = tasks.some_task(p1="test")
assert isinstance(maybe_result, State)
assert maybe_result.is_failed()
This allows the type-checker to verify that the
is_failed
method exists on
maybe_result
.