pierrejeambrun opened a new pull request, #67709:
URL: https://github.com/apache/airflow/pull/67709

   **Stacked on top of #67639** — only the final commit (``API: Add POST 
/dags/{dag_id}/dagRuns/clear...``) is in this PR's scope; the earlier commits 
fall out automatically once #67639 merges.
   
   ## Summary
   
   Adds ``POST /dags/{dag_id}/dagRuns/clear`` — the bulk analogue of
   ``POST /dags/{dag_id}/clearTaskInstances``. One round-trip clears N
   Dag Runs (optionally with a note applied to each) instead of the UI
   fanning out N requests today.
   
   ## Behavior
   
   - **URL ``dag_id``** is concrete or ``~``. With ``~``, every entry in
     ``dag_runs`` must carry its own ``dag_id``. With a specific Dag,
     entries may omit ``dag_id`` and inherit from the URL — the route
     rejects per-entity mismatches with **400**.
   - **Duplicates** in the ``dag_runs`` payload collapse to a single
     operation, mirroring ``BulkDagRunService.handle_bulk_delete``'s
     set-based semantics.
   - **``dry_run`` = ``True`` is the default**. Returns the union of
     affected ``TaskInstanceResponse`` rows (or ``NewTaskResponse``
     placeholders for the ``only_new`` path) across the listed runs
     without touching state.
   - **Real clear** returns a ``DAGRunCollectionResponse`` with the
     post-clear runs (all in ``queued`` state).
   - **``note``** is applied to each cleared run in the same transaction,
     mirroring the single-run ``note`` semantics introduced in #67639:
     ``None`` (default) leaves existing notes untouched; any string
     value (including ``""``) replaces them.
   - **Auth** uses a new ``requires_access_dag_run_clear_bulk`` dependency
     modelled on ``requires_access_dag_run_bulk`` — same per-Dag team
     caching, same wildcard-then-400 contract.
   
   ## Refactor
   
   To avoid duplicating the clear logic between the single-run and bulk
   routes, the per-run lookup / dry-run TI computation / clear+note step
   are pulled out of the single ``clear_dag_run`` route into
   ``services/public/dag_run.py`` as three helpers:
   
   - ``get_dag_run_and_dag_for_clear``
   - ``dry_run_clear_dag_run``
   - ``perform_clear_dag_run``
   
   The single-run route now composes them; the new bulk route loops over
   them per target.
   
   ## Tests
   
   ``TestBulkClearDagRuns`` (in ``test_dag_run.py``) covers:
   
   - specific-``dag_id`` URL with per-entity ``run_id`` only
   - ``~`` URL with per-entity ``(dag_id, run_id)`` across two Dags
   - ``dry_run`` collects affected TIs across multiple runs without
     mutating state
   - ``only_failed`` shrinks the dry-run preview
   - ``note`` is applied to each cleared run
   - ``~`` URL + missing per-entity ``dag_id`` → 400
   - specific URL + mismatched per-entity ``dag_id`` → 400
   - missing run → 404
   - ``only_new`` + ``only_failed`` mutually exclusive → 422
   - 401 / 403 paths
   
   ## Follow-up
   
   This is the backend half. A follow-up UI PR can collapse the existing
   ``useBulkClearDagRuns`` / ``useBulkClearDagRunsDryRun`` fan-out hooks
   to a single bulk call against this endpoint.
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes — Claude Code (Opus 4.7)
   
   Generated-by: Claude Code (Opus 4.7) 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]

Reply via email to