Skip to content

Show Dag bundle versions and refresh times in the UI - #72909

Merged
kaxil merged 4 commits into
apache:mainfrom
astronomer:dag-bundles-visibility
Sep 16, 2026
Merged

kaxil merged 4 commits into
apache:mainfrom
astronomer:dag-bundles-visibility

Conversation

@kaxil

@kaxil kaxil commented Sep 10, 2026 •

Copy link
Copy Markdown
Member

Problem

A Dag author pushes a commit and then has no way to tell whether Airflow has picked it up. The workflow today is: commit, push, then reload the Dags page until the import errors or the file details change. In deployments where Dag code viewing is disabled there is not even that -- the author is left guessing, including guessing what the bundle refresh interval is set to.

Nothing in the UI or the REST API exposes Dag bundle state, even though the dag_bundle table has recorded the version and the last refresh time since Airflow 3.0.

A per-Dag check covers less than it appears to. GET /dags/{dag_id}/dagVersions does report the new SHA for an ordinary commit, including one that leaves serialization untouched -- SerializedDagModel.write_dag refreshes the existing DagVersion's bundle_version in place on that path. What it cannot report is the case that matters most here: when every Dag in the commit fails to import, no write_dag runs at all, so DagVersion.bundle_version stays pinned to the last good commit while the bundle has plainly moved on. Alongside that, last_refreshed exists nowhere else per bundle, and neither view answers "has anything landed" without already knowing which Dag to look at.

Solution

GET /api/v2/dagBundles lists each bundle with the version Airflow currently holds, when a Dag processor last refreshed it, how many Dag import errors it has, its owning team, and whether it is still configured. A Dag Bundles page under Browse renders that and refreshes itself while open.

Field
version What the bundle reports as current -- for a Git bundle, the commit SHA of the tracking ref, comparable directly against what was deployed. null for bundles that do not support versioning.
last_refreshed When a Dag processor last successfully refreshed. Advances even when the version did not change, so it also says a processor is alive and looking at this bundle.
import_error_count Non-zero next to a version that just changed means the code was fetched but a Dag in it failed to import. null when the caller may not read import errors -- deliberately not 0.
bundle_url The bundle's view URL rendered at version, when one is configured.

Read-only on purpose. This adds no way to create, delete, enable or disable a bundle, so it introduces no new role and no new writable configuration surface -- it reads rows the Dag processor already writes. That keeps it clear of the objection raised on #61645, which is about runtime mutation of bundle configuration.

The endpoint also makes "wait until my commit is live" scriptable from a deployment pipeline, which is the other half of the same problem:

DEPLOYED=$(git rev-parse HEAD)
until [ "$(curl -sH "Authorization: Bearer $TOKEN" "$AIRFLOW_API/api/v2/dagBundles" \
            | jq -r '.dag_bundles[] | select(.name == "my_git_bundle") | .version')" = "$DEPLOYED" ]; do
  sleep 10
done

What it looks like

Pushing a commit and watching the row pick it up, with no reload and no navigation -- everything that changes on screen comes from the page's own polling:

Dag Bundles page updating live as a commit lands

A commit whose Dag fails to import. The version advances, because the fetch itself succeeded; the import-error count beside it is what says the new code is not actually running:

A bundle showing a freshly advanced commit alongside an import error

The version links to the commit it names, and a bundle dropped from the configuration keeps its last version and timestamp, flagged rather than removed:

The version cell linking to the commit, with the full SHA on hover

A deactivated bundle, still listed and marked inactive

Authorization -- the decision I would most like a second opinion on

A bundle is visible to a caller who can read at least one Dag recorded against it. The route carries requires_access_dag(method="GET"), and rows are filtered by PermittedDagBundleFilter, which is the existing PermittedDagFilter pattern applied to dag_bundle via the Dags inside it.

I deliberately did not add an AccessView.DAG_BUNDLES. It is the house style for admin-ish read views (Jobs, Plugins, Providers), and the enum's own comments explain why bundle-shaped things get one: there is no per-Dag key to authorize on. But it needs a FAB RESOURCE_DAG_BUNDLE seeded into roles, and seeding that admin- or op-only locks out the Dag authors this exists for.

I also rejected authorizing on is_authorized_dag(method="GET", details=DagDetails(id=None, team_name=...)), which was my first design. FAB treats method="GET" with no details.id as "may this user list Dags", which _is_authorized_list_dags answers True for anyone holding read on a single Dag, and FAB ignores team_name outright. Under that design one Dag's worth of access would have exposed every bundle in the deployment, bundle_url included -- the Git host, org and path of every other team's private repository. Today a rendered bundle URL is only reachable per-Dag through /dags/{dag_id}/dagVersions, so that would have been a genuine widening. Deriving the filter from readable Dags instead behaves identically across FAB, SimpleAuthManager and Keycloak rather than one of them silently opting out.

POST /api/v2/dagBundles/{bundle_name}/refresh in #72715 faces the same question and asked it of maintainers without an answer, so I am raising it rather than treating either choice as settled. If the answer is a dedicated resource, the change is contained to one dependency.

Two consequences of the Dag-derived filter, both documented:

  • A bundle from which no Dag has ever parsed successfully is not listed. If a brand new bundle does not appear, the Dag processor log is the place to look.
  • A bundle whose Dags have all since been deleted stays listed, because a stale DagModel row still names it. That is intentional: it is exactly when someone wants to see the bundle still being refreshed.

What this does not do

  • It cannot tell you a refresh is failing. bundle.refresh() raising is caught and logged, leaving last_refreshed at its last success with no error marker anywhere on dag_bundle, so "failing for an hour" looks identical to "not due yet". The docs say so plainly and give the two checks that do not need the refresh interval: compare a bundle against the other rows, since one processor refreshes all the bundles it owns in the same loop; and /api/v2/jobs?job_type=DagProcessorJob for whether a responsible processor is alive. A last_refresh_error column would fix it properly and is follow-up work -- it is a migration on dag_bundle, and Allow API clients to refresh Dag bundles #72715 is contesting that same table.
  • A new version does not mean the new Dags are running. The bundle is refreshed before its Dags are parsed, so a version can appear slightly before the Dags from it are serialized. The import-error count is what distinguishes "fetched and broken" from "fetched and fine".
  • refresh_interval is not exposed. Reading it in the api-server means import_string on provider bundle classes in a process that has no other reason to load bundle config. The live last_refreshed and a per-bundle refresh trigger answer the underlying question better than an interval does.
  • No active filter, no name search, no single-bundle route. Nothing on the page needs them.
  • The import-error count is not yet a link to the errors themselves; the Dags list has a bundle_name filter in the API but not in the UI, so wiring both is a follow-up.

Related: #61645, #72715, #60616.

@jayachandrakasarla

jayachandrakasarla commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

It would be great to have a button in this UI to run the airflow dags reserialize command. I’d be happy to raise a separate pull request to integrate this feature into this page if this is something you'd like to include in the Airflow UI.

@pierrejeambrun pierrejeambrun left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Super promising! Thanks.

Let me know when this is ready for review, the branch could use some cleaning. (trimming some verbose section, removing the newsfragment, clean the code etc.)

@kaxil
kaxil force-pushed the dag-bundles-visibility branch 2 times, most recently from fca2d1f to 5c3248b Compare September 14, 2026 17:10

@ephraimbuddy ephraimbuddy 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.

The added browser tests remain smoke checks: removing polling would leave them green. Tests also still miss denial of Dag VERSION access, and two import-error tests duplicate the same scenario.

Add a read-only GET /api/v2/dagBundles endpoint and a Dag Bundles page under
Browse, listing each bundle with the version Airflow currently holds, when a Dag
processor last refreshed it, its import-error count, and whether it is still
configured.

Dag authors deploying code had no way to tell whether Airflow had picked up their
commit short of reloading the Dags page until import errors or file details
changed -- and where Dag code viewing is disabled, not even that. Per-Dag views
cover less than they appear to: when every Dag in a commit fails to import no
serialization runs at all, so DagVersion.bundle_version stays pinned to the last
good commit while the bundle has plainly moved on. last_refreshed exists nowhere
else per bundle, and neither view answers "has anything landed" without already
knowing which Dag to look at.

A bundle is visible to a caller who can read at least one Dag recorded against
it, so no new authorization resource is introduced. import_error_count is counted
on the same terms as GET /importErrors -- errors in files the caller can read no
Dag in are excluded, and errors in files that never registered a Dag need the
admin-by-default view -- and bundle_url is withheld from callers who may not read
Dag versions.

The page polls at the configured auto-refresh interval, floored at ten seconds
since a bundle row changes at most once per its refresh interval, and stops
entirely when a deployment sets that interval to zero.

Also fixes a latent crash in DagBundleModel.render_url, which guarded str.format
against KeyError and ValueError only. A view_url_template is deployment-supplied
and unvalidated, so a positional placeholder raises IndexError, an attribute
placeholder AttributeError, and a null version makes subscript and format-spec
placeholders raise TypeError -- reachable today through DagVersion.bundle_url on
the dagVersions endpoint.
Addresses review feedback on the Dag Bundles page.

Deriving bundle visibility from readable Dags hid a bundle with no registered
Dag from everyone, admins included. That is the first-deploy-is-broken case:
configure a bundle, push a file that fails to import, and the bundle never
appears, so the import-error count added to diagnose exactly that is
unreachable. Such a bundle has no Dag to authorize against, so it is now gated
on the admin-by-default AccessView.IMPORT_ERRORS_ALL, the same view that governs
import errors for a file that never registered a Dag. The disjunct is additive
and stays in SQL, so Dag scoping still applies to every bundle that does have
Dags, and pagination and total_entries remain correct.

render_url guarded the no-version case with a "{version" substring test, which
also matches an escaped "{{version}}" and an unrelated "{version_label}" param.
Both render fine without a version, so the link was dropped when it should not
have been. Field names now come from string.Formatter().parse.

The docs claimed the version and import-error count together tell you whether a
commit parsed. They do not: errors are not recorded against a version, a file
whose parse exceeds dag_file_processor_timeout is killed without writing an
import-error row, and the count only covers errors the reader may see. Reworded,
and added a note that the Browse entry needs a FAB provider release carrying the
menu-item mapping, since without it the entry is hidden for every role.

Adds Playwright coverage for the page, which every sibling Browse page already
had. The page object addresses cells by column id rather than position, so
multi_team and the column-visibility menu cannot silently shift them.
Addresses the second round of review.

Deciding Dag-less bundle visibility with one unscoped IMPORT_ERRORS_ALL check
was wrong in both directions under a team-aware policy: a caller granted the
unscoped view saw every team's Dag-less bundles, and a caller granted only their
own team's saw none. The names are now resolved before pagination and authorized
one at a time against each bundle's own team, then passed into the query as an
allow-list, which is what get_import_errors already does for a file with no
registered Dag. The team lookup is the existing batched get_team_names.

Keycloak's TEAM_MENU_ITEMS omitted the new menu item, so team Viewer, User, Op
and Admin roles could reach the bundles through the API but never find the page
under Browse. It sits with DAGS in the base team set rather than the admin one,
since bundle visibility rides on Dag read, and is guarded for Airflow versions
predating the item.

The browser tests only checked the initial render, so deleting the refetch
logic left them green. Vitest fake-timer coverage now pins the ten-second floor,
a longer configured interval, zero disabling refresh, and a changed row
appearing after a tick; removing the interval fails three of the four. The
Browse navigation check stays in Playwright.

Also adds the missing case where a caller may read a Dag but not its versions,
asserting the bundle stays listed with a null url, and folds two import-error
tests that asserted the same thing into one that says which restriction each
exclusion depends on.
@kaxil
kaxil force-pushed the dag-bundles-visibility branch from 5c3248b to 8e53572 Compare September 15, 2026 21:00
… item

The provider compatibility jobs run the Keycloak tests against Airflow 3.0.6
through 3.3.1, where MenuItem has no DAG_BUNDLES member. The source already
handled that: the hasattr guard leaves the item out of TEAM_MENU_ITEMS. The test
did not, hard-coding "Dag Bundles" into the expected grants, so all four compat
jobs failed on a list the source was right to omit.

The expected resource names now follow the same guard the source does, so they
describe the grant on whichever Airflow is under test while still pinning the
rest of the list and its ordering.
@kaxil
kaxil merged commit d57b249 into apache:main Sep 16, 2026
156 checks passed
@kaxil
kaxil deleted the dag-bundles-visibility branch September 16, 2026 00:00
@github-actions

Copy link
Copy Markdown
Contributor

Backport failed to create: airflow-ctl/v0-1-test. View the failure log Run details

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
❌ airflow-ctl/v0-1-test Commit Link

You can attempt to backport this manually by running:

cherry_picker d57b249 airflow-ctl/v0-1-test

This should apply the commit to the airflow-ctl/v0-1-test branch and leave the commit in conflict state marking
the files that need manual conflict resolution.

After you have resolved the conflicts, you can continue the backport process by running:

cherry_picker --continue

If you don't have cherry-picker installed, see the installation guide.

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.

4 participants