Skip to content

fix(scheduler): skip asset-triggered dags without SerializedDagModel#64322

Merged
Lee-W merged 9 commits intoapache:mainfrom
leossantos:fix/asset-queue-missing-serialized-dag-guard
Apr 5, 2026
Merged

fix(scheduler): skip asset-triggered dags without SerializedDagModel#64322
Lee-W merged 9 commits intoapache:mainfrom
leossantos:fix/asset-queue-missing-serialized-dag-guard

Conversation

@leossantos
Copy link
Copy Markdown
Contributor

Port to main (Airflow 3) of the scheduler guard from #63546: DagModel.dags_needing_dagruns could treat asset-triggered DAGs as ready for a new run when they had AssetDagRunQueue rows but no SerializedDagModel in 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-memory adrq_by_dag / dag_statuses maps until serialization exists. AssetDagRunQueue rows are not deleted; the scheduler can re-evaluate on a later run. A DEBUG log records skipped DAGs (missing serialization). The dags_needing_dagruns docstring documents this behavior.

Tests: two TestDagModel cases cover missing SerializedDagModel (single and multiple DAGs), DEBUG log expectations, sorted dag_id list in the message, and assert asset_dag_run_queue row counts unchanged after dags_needing_dagruns.

related: #63546


Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

  • 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.

@leossantos leossantos requested review from XD-DENG and ashb as code owners March 27, 2026 18:18
@eladkal eladkal added this to the Airflow 3.2.0 milestone Mar 27, 2026
@eladkal eladkal added the type:bug-fix Changelog: Bug Fixes label Mar 27, 2026
@leossantos leossantos force-pushed the fix/asset-queue-missing-serialized-dag-guard branch from 0b227b5 to 38a59e0 Compare March 27, 2026 22:38
…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.
Split DagModel and AssetDagRunQueue inserts and flush after DagModel so foreign-key order matches production DB constraints in TestDagModel.
@leossantos leossantos force-pushed the fix/asset-queue-missing-serialized-dag-guard branch from 38a59e0 to 5f4bd8a Compare March 30, 2026 13:02
@leossantos
Copy link
Copy Markdown
Contributor Author

leossantos commented Mar 30, 2026

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!

leossantos and others added 2 commits March 31, 2026 09:38
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.
@leossantos
Copy link
Copy Markdown
Contributor Author

I've made adjustments to ensure the pre-commit checks pass.

@leossantos leossantos requested a review from Lee-W March 31, 2026 18:03
Copy link
Copy Markdown
Member

@Lee-W Lee-W left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mostly good, but needs to fix the CI

@potiuk potiuk marked this pull request as draft April 1, 2026 13:02
@potiuk
Copy link
Copy Markdown
Member

potiuk commented Apr 1, 2026

@leossantos This PR has been converted to draft because it does not yet meet our Pull Request quality criteria.

Issues found:

  • Other failing CI checks: Failing: Postgres tests: core / DB-core:Postgres:14:3.10:Core...Serialization, MySQL tests: core / DB-core:MySQL:8.0:3.10:Core...Serialization, Sqlite tests: core / DB-core:Sqlite:3.10:Core...Serialization, Low dep tests:core / All-core:LowestDeps:14:3.10:Core...Serialization. Run prek run --from-ref main locally to reproduce. See static checks docs.
  • ⚠️ Unresolved review comments: This PR has 1 unresolved review thread from maintainers: @Lee-W (MEMBER): 1 unresolved thread. Please review and resolve all inline review comments before requesting another review. You can resolve a conversation by clicking 'Resolve conversation' on each thread after addressing the feedback. See pull request guidelines.

What to do next:

  • The comment informs you what you need to do.
  • Fix each issue, then mark the PR as "Ready for review" in the GitHub UI - but only after making sure that all the issues are fixed.
  • There is no rush — take your time and work at your own pace. We appreciate your contribution and are happy to wait for updates.
  • Maintainers will then proceed with a normal review.

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.

@leossantos leossantos marked this pull request as ready for review April 1, 2026 19:07
@leossantos
Copy link
Copy Markdown
Contributor Author

I solved the issue and tested locally
image

@leossantos leossantos requested a review from Lee-W April 1, 2026 19:15
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 SerializedDagModel row, 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.

leossantos and others added 2 commits April 4, 2026 14:14
Co-authored-by: Jens Scheffler <95105677+jscheffl@users.noreply.github.com>
@jscheffl jscheffl added the backport-to-v3-2-test Mark PR with this label to backport to v3-2-test branch label Apr 4, 2026
@Lee-W Lee-W merged commit b91394a into apache:main Apr 5, 2026
82 checks passed
@boring-cyborg
Copy link
Copy Markdown

boring-cyborg bot commented Apr 5, 2026

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

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 5, 2026

Backport successfully created: v3-2-test

Note: As of Merging PRs targeted for Airflow 3.X
the committer who merges the PR is responsible for backporting the PRs that are bug fixes (generally speaking) to the maintenance branches.

In matter of doubt please ask in #release-management Slack channel.

Status Branch Result
v3-2-test PR Link

github-actions bot pushed a commit that referenced this pull request Apr 5, 2026
…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>
github-actions bot pushed a commit to aws-mwaa/upstream-to-airflow that referenced this pull request Apr 5, 2026
…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>
potiuk pushed a commit that referenced this pull request Apr 8, 2026
…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>
vatsrahul1001 pushed a commit that referenced this pull request Apr 8, 2026
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-to-v3-2-test Mark PR with this label to backport to v3-2-test branch type:bug-fix Changelog: Bug Fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants