Avoid false TriggerDagRunOperator conflicts after ambiguous trigger retry - #66911
Avoid false TriggerDagRunOperator conflicts after ambiguous trigger retry#66911hkc-8010 wants to merge 6 commits into
Conversation
jason810496
left a comment
There was a problem hiding this comment.
Thanks! The overall direction LGTM.
I agreed with not have auto-retry for the POST, but I feel we should check whether the DagRun existed before the actual POST call.
|
I marked it as draft to avoid adding this to 3.2.2 release before the follow-up fix. |
…_exists
Replace the custom _dag_run_exists helper (GET dag-runs/{dag_id}/{run_id} with
compatibility fallback for 405/422/5xx) with direct self.get_count(run_ids=[run_id])
calls. The dag-runs/count endpoint has been available since Airflow 3.0.0, so the
40-line compatibility layer is unnecessary.
Also removes _is_legacy_previous_dag_run_route_response, updates all trigger tests
to mock GET /dag-runs/count, and adds a run_ids query param assertion.
|
@jason810496 Addressed all four points — see commit 8a9259d:
Would appreciate a re-review. Thanks! |
|
@hkc-8010 A few things need addressing before review — see our Pull Request quality criteria.
No rush. Note: This comment was drafted by an AI-assisted triage tool and may contain mistakes. Once you have addressed the points above, an Apache Airflow maintainer — a real person — will take the next look at your PR. We use this two-stage triage process so that our maintainers' limited time is spent where it matters most: the conversation with you. Drafted-by: Claude Code (Opus 4.7); reviewed by @potiuk before posting |
|
@potiuk @jason810496 The earlier static-check failure appears to have been dependency lock drift after the branch fell behind main. I merged main into this branch, CI reran on the latest head, and all required checks are now green, including Would you mind taking another look when you get a chance? Thanks. |
jason810496
left a comment
There was a problem hiding this comment.
After thoroughly review again. I think we might don't even need to introduce the extra check here, the client-side DagRunAlreadyExists error is acceptable in this case IMHO.
The trade-off here is that to achieve the exactly-once trigger for the execution API client we need to introduce extra get count round-trip to probe and make sure there isn't same DagRun before.
However, TriggerDagRunOperator might be critical path / hot path for some users, the additional probe here cause more pressure for the API-server / DB and increase the latency.
Additionally, we can safely rely on foreign key constraint of RDBMS to ensure there will only be exactly one DagRun on the server-side.
It's more like a design choice instead of straightforward patch.
I lean toward to keep it as-is instead of applying this patch.
WDYT? @amoghrajesh, @kaxil
jason810496
left a comment
There was a problem hiding this comment.
Still waiting for final decision on #66911 (review) comment, mark as request changes in case of accidental merge.
Avoid retrying the non-idempotent trigger Dag run POST through the generic execution API retry layer.
When the trigger POST raises an ambiguous transport-level
httpx.RequestError, the client now probes the requested Dag run ID. If the run exists andreset_dag_run=False, it treats the trigger as successful. If the run is missing, it re-raises the original request error.This preserves direct
409 Conflictbehavior, includingDAGRUN_ALREADY_EXISTSand the existingreset_dag_run=Trueclear path.closes: #66905
Tests:
uv run --project task-sdk ruff format task-sdk/src/airflow/sdk/api/client.py task-sdk/tests/task_sdk/api/test_client.pyuv run --project task-sdk ruff check --fix task-sdk/src/airflow/sdk/api/client.py task-sdk/tests/task_sdk/api/test_client.pyuv run --project task-sdk pytest task-sdk/tests/task_sdk/api/test_client.py::TestDagRunOperations -qprek run --files task-sdk/src/airflow/sdk/api/client.py task-sdk/tests/task_sdk/api/test_client.pybreeze testing task-sdk-tests --python 3.10 task-sdk/tests/task_sdk/api/test_client.py::TestDagRunOperationsbreeze testing task-sdk-tests --python 3.10breeze ci selective-check --commit-ref HEAD --default-branch main --github-repository apache/airflowWas generative AI tooling used to co-author this PR?
Generated-by: OpenAI Codex following the guidelines
{pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.