sjyangkevin opened a new pull request, #61932: URL: https://github.com/apache/airflow/pull/61932
<!-- 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: http://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. 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: #58381 * related: #ISSUE --> closes: #58381 ### Issue In Airflow 2, task instance state transition such as `RUNNING`, `SUCCESS`, `SKIPPED`, `FAILED` were logged into the `log` table through the `TaskInstance` model methods. In Airflow 3, the task state update/management is moved to the execution API endpoints `ti_run` and `ti_update_state`. However, the endpoints were not wired up to create `log` records, resulting in missing audit logs for task instance state transitions. ### Fix Added `session.add(Log(...))` calls to both `ti_run` and `ti_update_state` when the task instance state is updated. The call will be executed in the same transaction as the state update in both endpoints. In `ti_run`, the audit log is placed inside the `else` branch such that duplicated requests, or conflict request, due to network glitch, will not be logged. In `ti_update_state`, the `TI` select query is updated to fetch `task_id`, `run_id`, and `map_index`. <img width="1650" height="631" alt="Screenshot from 2026-02-14 19-13-44" src="https://github.com/user-attachments/assets/7c67e47f-4a63-4600-ae61-1d9bcda19b04" /> ### Caveat The following fields in the `log` table are missing. Require extra query/join to fetch the following information. * `logical_date` (previously `execution_date`) * `owner` (the value is `airflow` in Airflow 2) * `owner_display_name` (this field is also empty for task state transition) * `extra` (`full_command` will not be available as it is not run/update through CLI; `hostname` is not available in `ti_update_state`) --- ### DAG Test Samples <img width="443" height="612" alt="Screenshot from 2026-02-14 22-13-16" src="https://github.com/user-attachments/assets/3371b6b9-21d5-4094-a3fa-0deabc843400" /> ##### 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 (please specify the tool below) Generated-by: [Antigravity] following [the guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions) The tool is used to analyze the existing test cases to understand the behavior of both `ti_run` and `ti_update_state`. It is also used to generate new test cases. --- * 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` or `{issue_number}.significant.rst`, in [airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments). -- 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]
