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

   closes: #76838
   
   An asset event emitted inside a task loop links its "Source" to 
`/dags/<dag_id>/runs/<run_id>/tasks/<task_id>`, without the loop coordinate. 
The task instance API rejects a looped task instance requested that way (`400: 
Select a region and index for this task instance`), so the link opens a "No 
Task Instance found" page, and every iteration's event gets the same link. 
`AssetEvent` renders the event lists on the asset page, the Dag overview, the 
dashboard, and the Dag run's and task instance's Asset Events tabs, so all of 
them are affected.
   
   ### Changes
   
   - **`AssetEventResponse`** gets `source_region_id` and 
`source_region_index`, read from the event's source task instance. They are 
`None` when the event has no source task instance (for example one created 
through the REST API) or that task instance no longer exists. Every try keeps 
its own task instance row with its region, so an event from an earlier try 
still resolves.
   - **`GET /assets/events`** and **`GET 
/dags/{dag_id}/dagRuns/{dag_run_id}/upstreamAssetEvents`** load those two 
columns in the same query (`joinedload(...).load_only(...)`, shared as 
`load_source_region()`), so the query count doesn't change; 
`test_should_respond_200` still asserts 6 queries.
   - **UI:** `AssetEvent` builds the source link with `getTaskInstanceLink()`, 
which adds `region_id` and `region_index` the same way the other task instance 
links do.
   - Regenerated the OpenAPI spec, the UI client and the `airflowctl` 
datamodels.
   
   ### Tests
   
   - `test_reports_the_source_task_instance_region`: an event whose source task 
instance is iteration 2 of a loop reports that region and index. It fails 
without the change (`KeyError: 'source_region_id'`).
   - The full-response expectations in `test_assets.py` and `test_dag_run.py` 
include the two new fields, and the mocked event in 
`TestPostAssetEventsTeamResolution` sets `source_task_instance=None`, as an 
API-created event has.
   - UI: `AssetEvent.test.tsx` checks the plain link and the link with the loop 
coordinate. The second test fails without the change.
   
   Verified on `apache/airflow:3.4.0` before the change: a loop emitting an 
event in each of 3 iterations shows three identical "Source" links, and each 
opens "No Task Instance found" with the 400 above.
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [x] Yes — Claude Code (Claude Opus 5.5)
   
   Generated-by: Claude Code (Claude 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]

Reply via email to