Skip to content

Apply note when clearing a Dag Run / task instances#67639

Merged
kaxil merged 2 commits into
apache:mainfrom
astronomer:feat/clear-endpoints-note
May 29, 2026
Merged

Apply note when clearing a Dag Run / task instances#67639
kaxil merged 2 commits into
apache:mainfrom
astronomer:feat/clear-endpoints-note

Conversation

@pierrejeambrun
Copy link
Copy Markdown
Member

@pierrejeambrun pierrejeambrun commented May 28, 2026

Today the Clear dialogs (single and bulk, both for Dag Runs and
Task Instances) issue two requests on confirm: first POST .../clear
to actually clear, then a follow-up PATCH .../dagRuns/{run_id} /
PATCH .../taskInstances/... to attach the note the user typed in
the dialog.

Fix this by adding the backend option to specify the 'note' when clearing. (TI already supported that). And wire this in the front-end so we only emit 1 request to clear TI/Run with a note.

Summary

  • Backend: DAGRunClearBody gains a note: str | None field
    (max length 1000). After the clear succeeds in clear_dag_run,
    if note is set we apply it to the cleared run with the same
    dag_run.note = (text, user_id) / dag_run_note.content = …
    shape that patch_dag_run already uses.

    ClearTaskInstancesBody already carries this field and already
    applies it via _patch_task_instance_note in the same
    transaction — that side is unchanged.

Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Opus 4.7)

Generated-by: Claude Code (Opus 4.7) following the guidelines

@boring-cyborg boring-cyborg Bot added area:airflow-ctl area:API Airflow's REST/HTTP API area:UI Related to UI/UX. For Frontend Developers. backport-to-airflow-ctl/v0-1-test labels May 28, 2026
@pierrejeambrun pierrejeambrun changed the title Apply note in one shot when clearing a Dag Run / task instances Apply note when clearing a Dag Run / task instances May 28, 2026
Both the single-run and bulk Clear dialogs used to issue two requests:
first ``POST .../clear`` to clear the run / task instances, then a
follow-up ``PATCH .../dagRuns/{run_id}`` or ``PATCH .../taskInstances/...``
to set the note typed in the dialog. That race-prone double-call goes
away here.

``ClearTaskInstancesBody`` already carries a ``note`` field that the
clear endpoint applies via ``_patch_task_instance_note`` in the same
transaction. This commit ports the same convention to
``DAGRunClearBody`` — adding ``note: str | None`` and applying it to
the cleared Dag Run in ``clear_dag_run`` after the clear succeeds.

Semantics match the bulk-update / patch convention:
``note=None`` (the default) leaves the existing note untouched; any
string value (including ``""``) replaces it. Dry-run never writes.

UI changes: ``ClearRunDialog``, ``ClearTaskInstanceDialog`` and
``useBulkClearDagRuns`` now pass ``note`` directly in the clear body
when it changed and drop their secondary ``patchDagRun`` /
``patchTaskInstance`` mutations. Bulk clear of task instances already
followed this pattern and is unchanged.
@pierrejeambrun pierrejeambrun force-pushed the feat/clear-endpoints-note branch from 11724be to 2b16eb3 Compare May 28, 2026 11:56
- UI: replace ``...(cond ? { note } : {})`` spreads with a direct
  ``note: <expr> ?? undefined`` / ternary in the request body — same
  serialized output (``undefined`` keys are dropped by JSON.stringify),
  one less object spread.
- Backend: drop the verbose ``description=`` on ``DAGRunClearBody.note``
  so its OpenAPI schema matches the existing patch-body ``note``
  fields. ``datamodel-code-generator`` was emitting two extra
  ``Note2`` / ``Note3`` ``RootModel`` classes purely because the
  description made the Field signature distinct; with it gone, all
  the ``note`` fields collapse back onto the single ``Note`` model
  in ``airflow-ctl/src/airflowctl/api/datamodels/generated.py``.
Comment thread airflow-core/src/airflow/ui/src/queries/useBulkClearDagRuns.ts
@kaxil kaxil merged commit 530bbb3 into apache:main May 29, 2026
308 of 389 checks passed
@kaxil kaxil deleted the feat/clear-endpoints-note branch May 29, 2026 19:54
@github-actions
Copy link
Copy Markdown
Contributor

Backport failed to create: airflow-ctl/v0-1-test. View the failure log Run details

Note: As of Merging PRs targeted for Airflow 3.X
the committer who merges the PR is responsible for backporting the PRs that are bug fixes (generally speaking) to the maintenance branches.

In matter of doubt please ask in #release-management Slack channel.

Status Branch Result
airflow-ctl/v0-1-test Commit Link

You can attempt to backport this manually by running:

cherry_picker 530bbb3 airflow-ctl/v0-1-test

This should apply the commit to the airflow-ctl/v0-1-test branch and leave the commit in conflict state marking
the files that need manual conflict resolution.

After you have resolved the conflicts, you can continue the backport process by running:

cherry_picker --continue

If you don't have cherry-picker installed, see the installation guide.

sunildataengineer pushed a commit to sunildataengineer/airflow that referenced this pull request May 30, 2026
* Apply note in one shot when clearing a Dag Run / task instances

Both the single-run and bulk Clear dialogs used to issue two requests:
first ``POST .../clear`` to clear the run / task instances, then a
follow-up ``PATCH .../dagRuns/{run_id}`` or ``PATCH .../taskInstances/...``
to set the note typed in the dialog. That race-prone double-call goes
away here.

``ClearTaskInstancesBody`` already carries a ``note`` field that the
clear endpoint applies via ``_patch_task_instance_note`` in the same
transaction. This commit ports the same convention to
``DAGRunClearBody`` — adding ``note: str | None`` and applying it to
the cleared Dag Run in ``clear_dag_run`` after the clear succeeds.

Semantics match the bulk-update / patch convention:
``note=None`` (the default) leaves the existing note untouched; any
string value (including ``""``) replaces it. Dry-run never writes.

UI changes: ``ClearRunDialog``, ``ClearTaskInstanceDialog`` and
``useBulkClearDagRuns`` now pass ``note`` directly in the clear body
when it changed and drop their secondary ``patchDagRun`` /
``patchTaskInstance`` mutations. Bulk clear of task instances already
followed this pattern and is unchanged.

* Address review feedback

- UI: replace ``...(cond ? { note } : {})`` spreads with a direct
  ``note: <expr> ?? undefined`` / ternary in the request body — same
  serialized output (``undefined`` keys are dropped by JSON.stringify),
  one less object spread.
- Backend: drop the verbose ``description=`` on ``DAGRunClearBody.note``
  so its OpenAPI schema matches the existing patch-body ``note``
  fields. ``datamodel-code-generator`` was emitting two extra
  ``Note2`` / ``Note3`` ``RootModel`` classes purely because the
  description made the Field signature distinct; with it gone, all
  the ``note`` fields collapse back onto the single ``Note`` model
  in ``airflow-ctl/src/airflowctl/api/datamodels/generated.py``.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:airflow-ctl area:API Airflow's REST/HTTP API area:UI Related to UI/UX. For Frontend Developers. backport-to-airflow-ctl/v0-1-test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants