Fire failure listeners when TriggerDagRunOperator API call fails - #70506
Open
ABiscuitttt wants to merge 3 commits into
Open
Fire failure listeners when TriggerDagRunOperator API call fails#70506ABiscuitttt wants to merge 3 commits into
ABiscuitttt wants to merge 3 commits into
Conversation
Contributor
Author
|
Some context on how we ran into this: we run a global failure-alert listener plugin that pages our on-call channel (Feishu/Lark) through the @hookimpl
def on_task_instance_failed(previous_state, task_instance, error):
if task_instance.state != TaskInstanceState.FAILED:
return # still up_for_retry; only alert on final failure
send_alert(task_instance, error) # internal notificationWhen a |
When TriggerDagRunOperator targets a nonexistent DAG (or the API server otherwise rejects the trigger with 403/5xx), the supervisor reports the error by raising AirflowRuntimeError from the TriggerDagRun comms round-trip. That raise happens inside run()'s `except DagRunTriggerException` handler, and an exception raised in an except handler is not caught by the sibling except clauses, so it escaped run() entirely. main() then never reached finalize() — the only place on_task_instance_failed and on_failure_callback listeners run — so the task showed FAILED in the UI (via the supervisor's exit-code fallback) while alerting plugins and failure callbacks were silently skipped. Route the error through the normal failure path instead, so the task returns a terminal state, finalize() fires the listeners, and retry policy is honored. closes: apache#63089
Airflow prose convention is "Dag", and the test module already imports TriggerDagRunOperator at the top level.
ABiscuitttt
force-pushed
the
fix-trigger-dagrun-failure-listeners
branch
from
July 28, 2026 02:05
6ea96f7 to
102c4be
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When
TriggerDagRunOperatortargets a nonexistent Dag (or the API server otherwise rejects the trigger with 403/5xx), the supervisor reports the error by raisingAirflowRuntimeErrorfrom theTriggerDagRuncomms round-trip. That raise happens insiderun()'sexcept DagRunTriggerExceptionhandler, and an exception raised in an except handler is not caught by the sibling except clauses — it escapedrun()entirely.main()then never reachedfinalize(), the only placeon_task_instance_failed/on_failure_callbacklisteners run. The task still showed FAILED in the UI (via the supervisor's exit-code fallback), but alerting plugins were silently skipped for exactly this failure mode.The fix routes the error through the normal failure path (
_handle_current_task_failed), so the task returns a terminal state,finalize()fires the listeners, and retry policy is honored (UP_FOR_RETRYwhen retries remain).Relationship to prior work on #63089: the reported
UnboundLocalErrorsymptom was already fixed by #67955 (thestatevariable is now initialized and theti.finishstats emission is guarded), and #63207 was an earlier, unmerged attempt at the full fix. What remains — and what this PR addresses — is the API error escapingrun()entirely, which silently skips failure listeners, failure callbacks, and retry handling.Regression tests cover both the no-retry (
FAILED) and retry (UP_FOR_RETRY) paths, asserting the terminal state reaches the supervisor instead of the error escapingrun().closes: #63089
Was generative AI tooling used to co-author this PR?
Generated-by: Kimi Code CLI following the guidelines