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

   ## Why
   
   - `GET /api/v2/eventLogs` returns `task_display_name: null` for REST API 
actions on a single task instance, such as marking it as success from the UI.
   - #59973 made `Log.task_instance` join on `dag_id`, `task_id`, `run_id` and 
`map_index`, but `action_logging` never stores `map_index`. These rows have a 
NULL map index and can never match a task instance.
   - The same rows show an empty Map Index column in the UI audit log, and 
filtering by map index does not find them.
   
   
   ## How
   
   - `action_logging` records the map index from the request path, query or 
body. It commits the row before the endpoint validates the request, so it 
leaves out any value that is not an integer, is below -1, or does not fit the 
column.
   - Each audit row still matches at most one task instance, because `(dag_id, 
task_id, run_id, map_index)` is unique. This keeps the fix from #59973, which 
stopped one audit row from matching every task instance with the same task_id.
   
   ## Verification
   
   1. Add demo dag
   
   ```bash
   mkdir -p files/dags
   cat > files/dags/audit_log_map_index_demo.py <<'EOF'
   from __future__ import annotations
   
   from airflow.sdk import dag, task
   
   
   @dag(schedule=None, tags=["audit-log-demo"])
   def audit_log_map_index_demo():
       @task(task_display_name="Load orders")
       def load_orders():
           return "orders loaded"
   
       @task(task_display_name="Load shard")
       def load_shard(shard: int):
           return shard
   
       load_orders()
       load_shard.expand(shard=[0, 1, 2])
   
   
   audit_log_map_index_demo()
   EOF
   ```
   
   2. Start Airflow
   
   ```
   breeze start-airflow --db-reset
   ```
   
   3. Trigger Dag and mark "Load shard" as failed.
   4. Check audit log.
   
   On main branch, the `Map Index` column is empty although `map_index` is in 
`Extra` field. The API shows null for `map_index` and `task_display_name` 
fields.
   
   <img width="1312" height="171" alt="Screenshot 2026-09-12 at 1 18 43 PM" 
src="https://github.com/user-attachments/assets/4e0f9adc-7b9c-4ce2-820d-a4eeba39809b";
 />
   <img width="1265" height="305" alt="Screenshot 2026-09-12 at 1 19 11 PM" 
src="https://github.com/user-attachments/assets/580589ff-842a-40c1-b359-388819d1de03";
 />
   
   
   On this branch, we get expected values.
   <img width="1312" height="172" alt="Screenshot 2026-09-12 at 1 21 41 PM" 
src="https://github.com/user-attachments/assets/4cb8e1d6-f717-497f-b636-795427ac7128";
 />
   <img width="1263" height="301" alt="Screenshot 2026-09-12 at 1 21 53 PM" 
src="https://github.com/user-attachments/assets/9f28a563-10c2-420f-a58c-e65b87df049b";
 />
   
    <!-- SPDX-License-Identifier: Apache-2.0
         https://www.apache.org/licenses/LICENSE-2.0 -->
   
   <!--
   Thank you for contributing!
   
   Please provide above a brief description of the changes made in this pull 
request.
   Write a good git commit message following this guide: 
https://chris.beams.io/posts/git-commit/
   
   Please make sure that your code changes are covered with tests.
   And in case of new features or big changes remember to adjust the 
documentation.
   
   For user-facing UI changes, please attach before/after screenshots (or a 
short
   screen recording) so reviewers can assess the visual impact.
   
   Feel free to ping (in general) for the review if you do not see reaction for 
a few days
   (72 Hours is the minimum reaction time you can expect from volunteers) - we 
sometimes miss notifications.
   
   In case of an existing issue, reference it using one of the following:
   
   * closes: #ISSUE
   * related: #ISSUE
   -->
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   <!--
   If generative AI tooling has been used in the process of authoring this PR, 
please
   change below checkbox to `[X]` followed by the name of the tool, uncomment 
the "Generated-by".
   -->
   
   - [X] Yes - Claude Code
   
   <!--
   Generated-by: [Tool Name] following [the 
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
   -->
   
   ---
   
   * Read the **[Pull Request 
Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)**
 for more information. Note: commit author/co-author name and email in commits 
become permanently public when merged.
   * For fundamental code changes, an Airflow Improvement Proposal 
([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals))
 is needed.
   * When adding dependency, check compliance with the [ASF 3rd Party License 
Policy](https://www.apache.org/legal/resolved.html#category-x).
   * For significant user-facing changes create newsfragment: 
`{pr_number}.significant.rst`, in 
[airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments).
 You can add this file in a follow-up commit after the PR is created so you 
know the PR number.
   


-- 
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