Apply note when clearing a Dag Run / task instances#67639
Merged
Conversation
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.
11724be to
2b16eb3
Compare
- 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``.
1 task
bbovenzi
approved these changes
May 29, 2026
kaxil
approved these changes
May 29, 2026
Contributor
Backport failed to create: airflow-ctl/v0-1-test. View the failure log Run detailsNote: As of Merging PRs targeted for Airflow 3.X In matter of doubt please ask in #release-management Slack channel.
You can attempt to backport this manually by running: cherry_picker 530bbb3 airflow-ctl/v0-1-testThis should apply the commit to the airflow-ctl/v0-1-test branch and leave the commit in conflict state marking After you have resolved the conflicts, you can continue the backport process by running: cherry_picker --continueIf 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``.
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.
Today the Clear dialogs (single and bulk, both for Dag Runs and
Task Instances) issue two requests on confirm: first
POST .../clearto actually clear, then a follow-up
PATCH .../dagRuns/{run_id}/PATCH .../taskInstances/...to attach the note the user typed inthe 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:
DAGRunClearBodygains anote: str | Nonefield(max length 1000). After the clear succeeds in
clear_dag_run,if
noteis set we apply it to the cleared run with the samedag_run.note = (text, user_id)/dag_run_note.content = …shape that
patch_dag_runalready uses.ClearTaskInstancesBodyalready carries this field and alreadyapplies it via
_patch_task_instance_notein the sametransaction — that side is unchanged.
Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code (Opus 4.7) following the guidelines