https://prefect.io logo
Title
s

scott

04/21/2023, 10:07 PM
Are
on_completion
and
on_failure
hooks ignored when a task state is
Cached
? That seems to be the case, but AFAIK there’s no docs (https://github.com/PrefectHQ/prefect/issues/8967)
1
r

Ryan Peden

04/21/2023, 11:25 PM
I think the answer to your question is yes - the hooks are ignored when a task already has a cached result. Looking in
engine.py
, the
on_completion
and
on_failure
hooks for tasks get called during the task run here. But if there's a cached result for a task, the Prefect API rejects the proposal to transition the task from PENDING -> RUNNING and instead returns the terminal state with the cached result attached. When that happens, the
state.is_running()
check here is false, and block of code with the hook call gets skipped.
s

scott

04/21/2023, 11:28 PM
Thanks very much 🙏 I wish there was a
on_exit
that would run no matter what the end state - but I’ve hacked something together to get around this (to trigger whether a task state is failed/completed/cached)
r

Ryan Peden

04/21/2023, 11:38 PM
That might be worth opening a GitHub issue for; it sounds like a reasonable feature request.
:upvote: 1
s

scott

04/21/2023, 11:38 PM
Okay, thanks