Skip to content

Read fresh Dag bundle state during refresh#69830

Merged
vatsrahul1001 merged 2 commits into
apache:mainfrom
fat-catTW:read-fresh-dag-bundle-state-during-refresh
Jul 24, 2026
Merged

Read fresh Dag bundle state during refresh#69830
vatsrahul1001 merged 2 commits into
apache:mainfrom
fat-catTW:read-fresh-dag-bundle-state-during-refresh

Conversation

@fat-catTW

@fat-catTW fat-catTW commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Why:

Dag processors may need to observe Dag bundle refresh state written by another processor while reusing an existing SQLAlchemy session. Loading DagBundleModel as an ORM entity can return an object already present in the session identity map, which risks reading stale last_refreshed or version values.

Solution:

Select only the needed bundle state columns instead of loading the full ORM entity. This avoids the ORM identity map for this lookup and reads last_refreshed and version as row values.

Added a regression test that first reads bundle state in one session, updates the same row from another session, and verifies the manager observes the updated values.

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

Generated-by: [Codex] 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.

Comment thread airflow-core/src/airflow/dag_processing/manager.py

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to ensure Dag Processor bundle refresh logic reads up-to-date DagBundleModel refresh state (last_refreshed, version) even when a SQLAlchemy Session may already have a cached ORM instance in its identity map.

Changes:

  • Update DagFileProcessorManager.get_bundle_state() to select only last_refreshed and version columns (row-based) rather than loading an ORM entity, avoiding identity-map staleness.
  • Add a regression test intended to demonstrate cross-session updates are observed when reusing a session.
  • Remove an obsolete TODO related to verifying “fresh record” behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
airflow-core/src/airflow/dag_processing/manager.py Switch bundle state lookup to a column-only select to avoid ORM identity-map caching.
airflow-core/tests/unit/dag_processing/test_manager.py Add regression coverage for observing updated bundle state after another session updates the row.

Comment thread airflow-core/tests/unit/dag_processing/test_manager.py Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@potiuk potiuk added the ready for maintainer review Set after triaging when all criteria pass. label Jul 18, 2026
@vatsrahul1001

Copy link
Copy Markdown
Contributor

LGTM!

@vatsrahul1001
vatsrahul1001 merged commit dd869c5 into apache:main Jul 24, 2026
78 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

Backport successfully created: v3-3-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-3-test PR Link

vatsrahul1001 pushed a commit that referenced this pull request Jul 24, 2026
* Read fresh Dag bundle state during refresh

* Make Dag bundle state freshness test deterministic



---------
(cherry picked from commit dd869c5)

Co-authored-by: fat-catTW <124506982+fat-catTW@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@fat-catTW

Copy link
Copy Markdown
Contributor Author

Thanks for the review.

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

Labels

area:DAG-processing backport-to-v3-3-test Backport to v3-3-test ready for maintainer review Set after triaging when all criteria pass.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants