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

   On MySQL, `Trigger.clean_unused()` reads the ids of unreferenced triggers 
and deletes them in a second statement. A task that defers onto one of those 
triggers in between has its `task_instance` row cascade-deleted through 
`task_instance.trigger_id ... ON DELETE CASCADE`. The run then loses the task 
without any log, and either deadlocks or finishes `success` with the task never 
executed (#72061). An asset watcher or callback that picks up the trigger in 
that window is affected the same way.
   
   `main` fixed this in #70961 by re-checking the reference predicates in the 
DELETE. That PR also batches the cleanup and adds a new `[triggerer]` option, 
which are not patch-release material. This PR backports only the re-check to 
the MySQL branch of `clean_unused()`. Postgres and SQLite already evaluate the 
predicates inside the DELETE.
   
   The new test is adapted from the one #70961 added. Just before `DELETE FROM 
trigger` runs, it attaches a deferred task instance, an asset watcher or a 
callback to the candidate trigger.
   
   Verified in Breeze:
   
   | Backend | Fix | `test_clean_unused_rechecks_new_references` | 
`test_trigger.py` |
   |---|---|---|---|
   | MySQL | applied | 3 passed | 44 passed |
   | MySQL | reverted | 3 failed: the task instance and asset watcher are 
deleted, the callback case raises `IntegrityError` | — |
   | SQLite | applied | passed | 44 passed |
   
   related: #72061, #70961
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes — Claude Code (Opus 5.5)
   
   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]

Reply via email to