fix(scheduler): skip asset-triggered dags without SerializedDagModel#64322
Conversation
0b227b5 to
38a59e0
Compare
…in dags_needing_dagruns Remove those dag_ids from the in-memory candidate set until serialization exists; retain AssetDagRunQueue rows and emit DEBUG logs. Add unit tests and a bugfix newsfragment.
…izedDagModel is unavailable
Split DagModel and AssetDagRunQueue inserts and flush after DagModel so foreign-key order matches production DB constraints in TestDagModel.
38a59e0 to
5f4bd8a
Compare
|
Hi! I've fixed the failing tests and made the necessary adjustments. Could someone please approve the workflow run to verify the fixes? Thanks for the help! |
Co-authored-by: Wei Lee <weilee.rx@gmail.com>
Combine the missing-from-serialized set check with a walrus assignment and improve the debug message when DagRun creation is skipped for DAGs with queued asset events but no SerializedDagModel row.
|
I've made adjustments to ensure the pre-commit checks pass. |
Lee-W
left a comment
There was a problem hiding this comment.
mostly good, but needs to fix the CI
|
@leossantos This PR has been converted to draft because it does not yet meet our Pull Request quality criteria. Issues found:
What to do next:
Converting a PR to draft is not a rejection — it is an invitation to bring the PR up to the project's standards so that maintainer review time is spent productively. There is no rush — take your time and work at your own pace. We appreciate your contribution and are happy to wait for updates. If you have questions, feel free to ask on the Airflow Slack. |
There was a problem hiding this comment.
Pull request overview
Ports an Airflow scheduler guard to prevent premature asset-triggered DagRun creation when AssetDagRunQueue has queued events but the DAG is not yet available in SerializedDagModel (e.g., during a DAG processor parse/serialize window).
Changes:
- Skip asset-triggered DAGs that have ADRQ rows but no corresponding
SerializedDagModelrow, leaving ADRQ rows intact for later re-evaluation. - Add a DEBUG log listing skipped DAG IDs (sorted) when serialization is missing.
- Add unit tests covering missing-serialization scenarios (single/multiple DAGs), expected debug logging, and ensuring ADRQ row counts are unchanged; add a bugfix newsfragment.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| airflow-core/src/airflow/models/dag.py | Adds the guard to omit ADRQ-backed DAGs missing serialization and logs skipped DAG IDs. |
| airflow-core/tests/unit/models/test_dag.py | Adds regression tests validating skip behavior, debug logging, and no ADRQ deletions. |
| airflow-core/newsfragments/64322.bugfix.rst | Documents the scheduler bugfix in release notes. |
Co-authored-by: Jens Scheffler <95105677+jscheffl@users.noreply.github.com>
|
Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions. |
Backport successfully created: v3-2-testNote: As of Merging PRs targeted for Airflow 3.X In matter of doubt please ask in #release-management Slack channel.
|
…zedDagModel (#64322) * fix(scheduler): skip asset-triggered dags without SerializedDagModel in dags_needing_dagruns Remove those dag_ids from the in-memory candidate set until serialization exists; retain AssetDagRunQueue rows and emit DEBUG logs. Add unit tests and a bugfix newsfragment. * fix(scheduler): prevent premature asset-triggered DagRuns when SerializedDagModel is unavailable * test(dag): persist DagModel before AssetDagRunQueue in unit tests Split DagModel and AssetDagRunQueue inserts and flush after DagModel so foreign-key order matches production DB constraints in TestDagModel. * Apply suggestions from code review Co-authored-by: Wei Lee <weilee.rx@gmail.com> * refactor(dag): clarify ADRQ skip log and condense serialized-DAG guard Combine the missing-from-serialized set check with a walrus assignment and improve the debug message when DagRun creation is skipped for DAGs with queued asset events but no SerializedDagModel row. * test(models): align caplog assertions with updated serialized dag warnings * test(dag): align ADRQ missing-serialized log assertion with message text * Apply suggestion from @jscheffl Co-authored-by: Jens Scheffler <95105677+jscheffl@users.noreply.github.com> * chore(newsfragments): remove 64322.bugfix.rst --------- (cherry picked from commit b91394a) Co-authored-by: Leonardo Soares <leoss33@outlook.com.br> Co-authored-by: Wei Lee <weilee.rx@gmail.com> Co-authored-by: Jens Scheffler <95105677+jscheffl@users.noreply.github.com>
…zedDagModel (apache#64322) * fix(scheduler): skip asset-triggered dags without SerializedDagModel in dags_needing_dagruns Remove those dag_ids from the in-memory candidate set until serialization exists; retain AssetDagRunQueue rows and emit DEBUG logs. Add unit tests and a bugfix newsfragment. * fix(scheduler): prevent premature asset-triggered DagRuns when SerializedDagModel is unavailable * test(dag): persist DagModel before AssetDagRunQueue in unit tests Split DagModel and AssetDagRunQueue inserts and flush after DagModel so foreign-key order matches production DB constraints in TestDagModel. * Apply suggestions from code review Co-authored-by: Wei Lee <weilee.rx@gmail.com> * refactor(dag): clarify ADRQ skip log and condense serialized-DAG guard Combine the missing-from-serialized set check with a walrus assignment and improve the debug message when DagRun creation is skipped for DAGs with queued asset events but no SerializedDagModel row. * test(models): align caplog assertions with updated serialized dag warnings * test(dag): align ADRQ missing-serialized log assertion with message text * Apply suggestion from @jscheffl Co-authored-by: Jens Scheffler <95105677+jscheffl@users.noreply.github.com> * chore(newsfragments): remove 64322.bugfix.rst --------- (cherry picked from commit b91394a) Co-authored-by: Leonardo Soares <leoss33@outlook.com.br> Co-authored-by: Wei Lee <weilee.rx@gmail.com> Co-authored-by: Jens Scheffler <95105677+jscheffl@users.noreply.github.com>
…zedDagModel (#64322) (#64738) * fix(scheduler): skip asset-triggered dags without SerializedDagModel in dags_needing_dagruns Remove those dag_ids from the in-memory candidate set until serialization exists; retain AssetDagRunQueue rows and emit DEBUG logs. Add unit tests and a bugfix newsfragment. * fix(scheduler): prevent premature asset-triggered DagRuns when SerializedDagModel is unavailable * test(dag): persist DagModel before AssetDagRunQueue in unit tests Split DagModel and AssetDagRunQueue inserts and flush after DagModel so foreign-key order matches production DB constraints in TestDagModel. * Apply suggestions from code review * refactor(dag): clarify ADRQ skip log and condense serialized-DAG guard Combine the missing-from-serialized set check with a walrus assignment and improve the debug message when DagRun creation is skipped for DAGs with queued asset events but no SerializedDagModel row. * test(models): align caplog assertions with updated serialized dag warnings * test(dag): align ADRQ missing-serialized log assertion with message text * Apply suggestion from @jscheffl * chore(newsfragments): remove 64322.bugfix.rst --------- (cherry picked from commit b91394a) Co-authored-by: Leonardo Soares <leoss33@outlook.com.br> Co-authored-by: Wei Lee <weilee.rx@gmail.com> Co-authored-by: Jens Scheffler <95105677+jscheffl@users.noreply.github.com>
…zedDagModel (#64322) (#64738) * fix(scheduler): skip asset-triggered dags without SerializedDagModel in dags_needing_dagruns Remove those dag_ids from the in-memory candidate set until serialization exists; retain AssetDagRunQueue rows and emit DEBUG logs. Add unit tests and a bugfix newsfragment. * fix(scheduler): prevent premature asset-triggered DagRuns when SerializedDagModel is unavailable * test(dag): persist DagModel before AssetDagRunQueue in unit tests Split DagModel and AssetDagRunQueue inserts and flush after DagModel so foreign-key order matches production DB constraints in TestDagModel. * Apply suggestions from code review * refactor(dag): clarify ADRQ skip log and condense serialized-DAG guard Combine the missing-from-serialized set check with a walrus assignment and improve the debug message when DagRun creation is skipped for DAGs with queued asset events but no SerializedDagModel row. * test(models): align caplog assertions with updated serialized dag warnings * test(dag): align ADRQ missing-serialized log assertion with message text * Apply suggestion from @jscheffl * chore(newsfragments): remove 64322.bugfix.rst --------- (cherry picked from commit b91394a) Co-authored-by: Leonardo Soares <leoss33@outlook.com.br> Co-authored-by: Wei Lee <weilee.rx@gmail.com> Co-authored-by: Jens Scheffler <95105677+jscheffl@users.noreply.github.com>

Port to main (Airflow 3) of the scheduler guard from #63546:
DagModel.dags_needing_dagrunscould treat asset-triggered DAGs as ready for a new run when they hadAssetDagRunQueuerows but noSerializedDagModelin the same evaluation window. The asset timetable / condition path was not applied consistently for those DAGs, which could allow premature asset-triggered DagRuns while the DAG processor was mid–parse cycle.This change removes such
dag_ids from the in-memoryadrq_by_dag/dag_statusesmaps until serialization exists.AssetDagRunQueuerows are not deleted; the scheduler can re-evaluate on a later run. A DEBUG log records skipped DAGs (missing serialization). Thedags_needing_dagrunsdocstring documents this behavior.Tests: two
TestDagModelcases cover missingSerializedDagModel(single and multiple DAGs), DEBUG log expectations, sorteddag_idlist in the message, and assertasset_dag_run_queuerow counts unchanged afterdags_needing_dagruns.related: #63546
Was generative AI tooling used to co-author this PR?
{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.