ethanstoner opened a new pull request, #73682:
URL: https://github.com/apache/airflow/pull/73682
When a backfill reprocesses an existing Dag run (`reprocess_behavior` set to
`failed` or `completed`), `_handle_clear_run` clears the run and re-tags it as
a backfill run by updating `backfill_id`, `run_type` and `triggered_by`. It
never received the backfill's `triggering_user_name`, so a reprocessed run
keeps whatever it had before (`None` for a scheduled run). Runs the same
backfill creates fresh do get the user, so a single backfill ends up with some
runs attributed to the person who started it and some attributed to no one.
That is the "Triggering User Name" half of #62126.
This passes `triggering_user_name` through to `_handle_clear_run` and sets
it in the same `UPDATE` as `triggered_by`.
The other half of the issue, reprocessed runs keeping their `scheduled__...`
run_id, is deliberately not changed here. `run_type` is already `backfill`, and
renaming the run_id of an existing run would mean rewriting the task instance
rows that reference it.
related: #62126
### Reproduction (on `main`, before this change)
`test_reprocess_behavior[completed]` seeds `scheduled_2021-01-05` (success),
`scheduled_2021-01-06` (failed) and `scheduled_2021-01-07` (running), then
backfills 2021-01-03 to 2021-01-09 as user `pytest`. Listing `(run_id,
triggering_user_name)` for the runs in the backfill:
```
('backfill__2021-01-04T00:00:00+00:00', 'pytest')
('backfill__2021-01-05T00:00:00+00:00', 'pytest')
('scheduled_2021-01-05', None)
('scheduled_2021-01-06', None)
('backfill__2021-01-09T00:00:00+00:00', 'pytest')
('backfill__2021-01-10T00:00:00+00:00', 'pytest')
```
The two reprocessed runs have no triggering user.
### Testing
One assertion added to the existing parametrized `test_reprocess_behavior`
in `airflow-core/tests/unit/models/test_backfill.py`: every run in the backfill
has `triggering_user_name == "pytest"`.
- With `backfill.py` reverted to `main`:
`test_reprocess_behavior[failed-5-exc_reasons1]` and
`test_reprocess_behavior[completed-6-exc_reasons2]` fail, and `[none-4-...]`
passes because nothing is reprocessed in that mode.
- With the fix: `uv run --project airflow-core pytest
airflow-core/tests/unit/models/test_backfill.py`, 88 passed.
- The UI backfill route tests (`routes/ui/test_backfills.py`) pass. Six
tests in `cli/commands/test_backfill_command.py` fail in my local environment
on a `FixedTimezone` vs `Timezone('UTC')` mismatch in the mocked
`_create_backfill` call. They fail the same way with `backfill.py` reverted to
`main`, so they are unrelated to this change.
- `prek run --files` on both changed files: all hooks pass, including
`mypy-airflow-core`, except `check-tests-in-the-right-folders`, which did not
run because `breeze` is not installed locally. No test files were added or
moved.
No newsfragment. This is a small bugfix to audit metadata, and I'm happy to
add one if a maintainer wants it.
---
##### Was generative AI tooling used to co-author this PR?
- [X] Yes (please specify the tool below)
Generated-by: Claude Code (Opus 5.5) 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]