rmfrall opened a new pull request, #77730:
URL: https://github.com/apache/airflow/pull/77730
### Details
`PATCH /execution/task-instances/{id}/dag-run-note` (from #69403) resolves
the DagRun
through the calling task instance. That resolution is a plain join on
`TaskInstance`,
so it is subject to the loader criteria that hide archived attempts from
every
`TaskInstance` query unless `include_all_attempts` is set
(`_restrict_to_current_attempts`
in `models/taskinstance.py`): the moment the attempt is cleared and
archived, the join
finds nothing and the request is answered with 404.
The note update then fails end to end for a task that is still executing:
```
task code (ti.get_dagrun().note = ... / TaskInstance.update_dagrun_note)
-> SUPERVISOR_COMMS.send(UpdateDagRunNote) # no guard
-> supervisor _handle_update_dag_run_note # no guard
-> client.task_instances.update_dagrun_note # no guard
<- 404 -> ErrorResponse frame -> AirflowRuntimeError raised inside the
task's
own note update call
```
So a long-running task that reports progress into the run note (#69403's use
case) and
gets cleared by an operator mid-flight blows up with a confusing
`AirflowRuntimeError`
traceback in place of the note, instead of leaving the note on the run for
the next
attempt. The heartbeat route already answers archived attempts with 410 and
the
supervisor kills the worker on it, but there is a full heartbeat interval of
window
where a note update still slips through.
The note belongs to the DagRun rather than to the attempt, so this resolves
the caller
among all its attempts, exactly like the DagVersion lookups in `DagRun`
already do
(`dag_versions`: "Return the Dag versions used by any attempt of this
DagRun, current
or archived"). A task instance id that never existed still returns 404, a
null note
still leaves a user-authored note untouched, and an empty note still clears
it — the
rest of the endpoint's contract is unchanged.
### Tests
- `test_update_dag_run_note_archived_task_instance_still_updates_note`
(execution API):
an id archived by `prepare_db_for_next_try` gets 204 and the note lands on
the DagRun
unattributed.
- `test_update_dag_run_note_null_note_for_archived_task_instance_is_noop`
(execution
API): a null note on an archived attempt keeps a user-authored note
untouched.
- Existing class tests unchanged: create / update / clear / null / not-found
(404) /
too-long (422) all still pass.
Full regression locally in a one-off container: `TestTIDagRunNoteUpdate` 8
passed,
archived/cleared sibling tests (heartbeat, RTIF, task state) 6 passed,
execution API
`test_task_instances.py` full file 363 passed / 0 failed / 7 skipped
(db-backed), ruff
check + format green.
### Committers
- [ ] I acknowledge that I am a maintainer/committer of the Apache Airflow
project.
---
---
##### Was generative AI tooling used to co-author this PR?
- [X] Yes — TeleAgent
Generated-by: TeleAgent 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]