Skip to content

Add a regression test for WITH in the asset orphanage DELETE - #75127

Merged
shahar1 merged 1 commit into
apache:mainfrom
DavidAmsellem:fix-asset-orphanage-cte-in-dml
Nov 6, 2026
Merged

shahar1 merged 1 commit into
apache:mainfrom
DavidAmsellem:fix-asset-orphanage-cte-in-dml

Conversation

@DavidAmsellem

@DavidAmsellem DavidAmsellem commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

The asset orphanage pass runs on every scheduler loop and deletes orphaned assets from asset_active. MySQL-compatible backends whose planner does not support WITH in DML (Vitess, PlanetScale) reject that DELETE when it is built from a CTE, with VT12001: unsupported: WITH expression in DELETE statement, so the scheduler crash-loops on them (#72187).

This PR first changed the orphan query from a CTE to a subquery. #75404 has since made the same change on both queries and was merged, so this PR is now reduced to the regression test, as agreed in #75404 (comment).

test_asset_orphaning_delete_has_no_cte captures the DELETE the orphanage pass sends on asset_active, compiles it with the MySQL dialect and checks that it has no WITH clause, as suggested in the review of #72188. None of the existing orphanage tests looks at the generated SQL, so a CTE coming back on that side would otherwise only show up on those backends.

closes: #72187

Tested:

  • The asset orphanage tests in test_scheduler_job.py (-k orphan, 17 tests) pass on main (4138878) with SQLite.
  • With orphan_query changed back to .cte(), the new test fails and the other 16 still pass.
  • Static checks pass (prek, pre-commit stage).

Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Opus 5.5)

Generated-by: Claude Code (Opus 5.5) following the guidelines


  • Read the 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) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.

🤖 Generated with Claude Code

@boring-cyborg

boring-cyborg Bot commented Oct 19, 2026

Copy link
Copy Markdown

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide
Here are some useful points:

  • Pay attention to the quality of your code (ruff, mypy and type annotations). Our prek-hooks will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example Dag that shows how users should use it.
  • Consider using Breeze environment for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
  • Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: [email protected]
    Slack: https://s.apache.org/airflow-slack

@DavidAmsellem
DavidAmsellem force-pushed the fix-asset-orphanage-cte-in-dml branch 2 times, most recently from eee6416 to eb0d026 Compare October 26, 2026 09:56
@DavidAmsellem DavidAmsellem changed the title Avoid a CTE in the asset orphanage DELETE Add a regression test for WITH in the asset orphanage DELETE Oct 26, 2026
MySQL-compatible backends whose planner does not support WITH in DML,
such as Vitess and PlanetScale, reject the asset orphanage DELETE at plan
time, and the scheduler crash-loops on them. apache#75404 made the orphan query
a subquery, which removed the WITH. The test captures that DELETE,
compiles it with the MySQL dialect and checks it has no WITH clause, so a
CTE coming back on that side fails a test instead of the scheduler.
@shahar1
shahar1 force-pushed the fix-asset-orphanage-cte-in-dml branch from eb0d026 to 6f49323 Compare November 6, 2026 14:28
@shahar1
shahar1 enabled auto-merge (squash) November 6, 2026 14:29
@shahar1
shahar1 merged commit c8e0165 into apache:main Nov 6, 2026
71 checks passed
@boring-cyborg

boring-cyborg Bot commented Nov 6, 2026

Copy link
Copy Markdown

Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Scheduler crash-loops on MySQL-compatible backends without CTE-in-DML support (e.g. Vitess): asset orphanage DELETE uses WITH

2 participants