zhengdaodeguL opened a new pull request, #77129:
URL: https://github.com/apache/airflow/pull/77129
A deferrable `ExternalTaskSensor` kept waiting after one of its monitored
upstream tasks failed. With two upstream tasks, `allowed_states=["success"]`
and `failed_states=["failed"]`, one task failed and the other successful:
the non-deferrable sensor raises `ExternalTaskFailedError`, but the
deferrable trigger kept polling instead of emitting a failed event. The same
applied to `skipped_states`.
Root cause: `WorkflowTrigger._get_count_af_3()` returned
`int(count / len(self.external_task_ids))`. `get_ti_count()` returns the
aggregate `COUNT(*)` of matching TaskInstance rows, so one matching task out
of two is a raw count of 1 — truncated to `int(1 / 2) = 0`, and the trigger
missed the partial failure or skip.
This PR:
- Makes `_get_count_af_3()` return the aggregate count for explicit task IDs
without integer division, so a positive failed/skipped count means any
matching task.
- Adjusts the success check in `WorkflowTrigger.run()` to compare the
Airflow 3 task-ID allowed count against
`len(task_ids) * len(runs)` (all tasks in all runs must match), while
keeping the previous run-count threshold for Airflow 2, Dag checks, and
task-group checks.
- Adds a parametrized regression test for a partial failure, a partial skip,
and the all-tasks-allowed case, and updates the existing `_get_count_af_3`
assertion from the normalized count to the aggregate count.
Verification:
`providers/standard/tests/unit/standard/triggers/test_external_task.py`
passes (17 passed, 8 skipped — the skipped cases are Airflow 2-only or
otherwise explicitly skipped). The new partial-failure, partial-skip, and
updated count assertions fail on the base commit. The issue's reproduction
(mocked `get_ti_count` returning 1, intercepted `asyncio.sleep`) emits
`{'status': 'failed'}` after the fix instead of polling again. `ruff check`
and `ruff format --check` pass on both changed files.
Note for reviewers: open PR #73986 refactors the same `_get_count_af_3`
method (extracting `_get_ti_count`/`_get_dr_count`/`_get_task_group_states`
helpers for the HTTP trigger subclass) but retains the old division, so it
does not fix this bug; the two PRs touch the same lines and may conflict.
closes: #77116
---
##### Was generative AI tooling used to co-author this PR?
- [X] Yes (Codex)
Generated-by: Codex following [the
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]