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

   ## Summary
   Fixes #66177.
   
   This prevents `airflow db clean --skip-archive` from hanging when a delete 
fails while cleaning up a temporary archive table.
   
   ## What changed
   When `_do_delete()` encounters an exception during the source-table delete:
   - it now calls `session.rollback()` before cleanup,
   - then drops the temporary archive table using `session.connection()` 
instead of `session.get_bind()`.
   
   This releases MySQL metadata locks held by the failed transaction before 
attempting `DROP TABLE`, avoiding the self-deadlock described in #66177.
   
   ## Behavior impact
   This does not change successful cleanup behavior.
   For the failure case described in #66177, the command now fails fast and 
surfaces the original database error instead of hanging indefinitely. The 
change does not make FK-pinned `dag_version` rows deletable; it only prevents 
the deadlock and cleans up the temporary archive table safely.
   
   ## Tests
   Added regression coverage:
   - 
`TestDBCleanup::test_skip_archive_failure_rolls_back_before_drop_on_session_connection`
   The test verifies that:
   - rollback happens after the delete failure,
   - the temporary archive table is dropped via the session connection,
   - rollback happens before acquiring the connection used for the drop.
   
   Local validation:
   ```bash
   uvx ruff format airflow-core/src/airflow/utils/db_cleanup.py 
airflow-core/tests/unit/utils/test_db_cleanup.py
   uvx ruff check --fix airflow-core/src/airflow/utils/db_cleanup.py 
airflow-core/tests/unit/utils/test_db_cleanup.py
   Both passed.
   
   I could not run the focused pytest in this cloud environment because native 
test dependencies/Docker were unavailable, but the regression test is included 
for CI.
   
   Was generative AI tooling used to co-author this PR?
   Yes — GPT-5.5
   Generated-by: GPT-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