Skip to content

Scope plugin views on any entity field, not a fixed criteria set - #74278

Merged
bbovenzi merged 1 commit into
apache:mainfrom
astronomer:pr/applies-to-field-paths
Oct 7, 2026
Merged

bbovenzi merged 1 commit into
apache:mainfrom
astronomer:pr/applies-to-field-paths

Conversation

@bbovenzi

@bbovenzi bbovenzi commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Refactor applies_to from @dheerajturaga's PR in #69148. Instead of hard coding 5 possible fields to filter a plugin tab. We will allow any field on the dag, dag_run, task, or task_instance models. This should give greater flexibility for fully custom plugins.

For example, a plugin that only applies to failed task instances on dags with my team's tag:

destination: "task_instance"
applies_to: {"state": ["failed", "upstream_failed"], "dag.tags.name": ["my-team"]}

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

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

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

@bbovenzi overall I like the direction, this gives much more flexibility! I tested this with a bunch of examples and it works well. Ive added some minor comments, nothing blocking. Thanks for addressing this gap!

The five criteria `applies_to` accepted could not express the scoping plugin
authors actually want. The most-asked-for case -- offer a tab or panel only on a
failed Dag Run or Task Instance -- was impossible, since state was not among
them, and no finite list of criteria will stay ahead of what Airflow exposes on
an entity.

`applies_to` has not shipped in an airflow-core release yet, so the closed set
can be replaced outright rather than grown, and no plugin author has to migrate
off it later.

This is a trade rather than a pure win, and it is worth being explicit about
what is given up. A fixed vocabulary could be checked exhaustively; paths are
resolved against the API response, so they can only be checked as far as the
response models describe themselves -- below a field typed as a bare dict, such
as `class_ref`, a wrong path cannot be told from a right one. A path that names
nothing is skipped at match time, which widens the scope rather than narrowing
it, so the failure is a view appearing where it should not. Validating paths
when plugins load, with a suggested correction, is what keeps that debuggable.

Matching stays equality-only. "Not successful" and "longer than five minutes"
are the obvious next asks and neither is expressible here; they need evaluation
the browser cannot do from the records on the page.

Co-Authored-By: Claude <[email protected]>
@bbovenzi
bbovenzi force-pushed the pr/applies-to-field-paths branch from 900579f to 354ff47 Compare October 6, 2026 16:46
@bbovenzi
bbovenzi merged commit 77e0906 into apache:main Oct 7, 2026
159 checks passed
@bbovenzi
bbovenzi deleted the pr/applies-to-field-paths branch October 7, 2026 19:22
@github-actions

github-actions Bot commented Oct 7, 2026

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 77e0906 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.

@bbovenzi bbovenzi mentioned this pull request Oct 7, 2026
1 task done
bbovenzi added a commit to astronomer/airflow that referenced this pull request Oct 8, 2026
Several things shipped with the field-path scoping in apache#74278 that review
caught after it merged, plus two fixes that depend on work landing since.

The troubleshooting steps name `airflow plugins list`, which does not exist --
`plugins` takes no subcommand -- so anyone following them to find out why a
view is not scoped as expected gets an argparse error instead.

The operator section recommends leaving `operator` and `class_ref.class_name`
unqualified so each page reads its own record, which is right, but the
load-time check then reports the one the page lacks as a path that will make
the view "appear in more places than intended". That is untrue for this block:
the other path is what scopes this destination. Following the documentation
should not produce a warning saying the documentation is wrong. The check now
tells a path that names no field anywhere -- a misspelling -- apart from one
that names a real field on a record this destination does not have, and says
only what is true of each. The section leads with one view per destination,
which needs no such reasoning, and keeps the single block as the shorter form.

A path that matches no field at all now withholds the view instead of loading
it. The browser cannot tell a misspelling from a field this page's record
simply does not have -- a block shared across destinations relies on the
latter being skipped -- so it skips both, and skipping widens the scope. A
typo therefore showed the view everywhere, the opposite of what its author
asked for. The response models are in hand when plugins load, so the two are
distinguishable there: a field no record has cannot be anything but a mistake,
while one a sibling record has is the shared-block pattern and still loads. A
view that disappears gets noticed; one on every page looks deliberate.

Validation also edited the plugin author's own `applies_to` dictionary to drop
null values. Harmless in isolation, but a plugin may pass one dictionary to
several views, and rewriting it is not this code's to do.

Which record an unqualified path is rooted at is also decided twice: once when
plugins load, to choose what to validate, and again in the browser, to choose
what to match. Nothing at runtime notices when the two tables disagree -- a
destination only one of them knows about makes every path on it unevaluable,
which shows the view everywhere instead of scoping it, and would surface later
as someone else's bug. A prek check compares them, so that drift fails before
it merges.

Scoping a task-level view on `task.*` judged historical task instances by the
Dag's definition today, so a view scoped to an operator stopped appearing on
the runs that actually used it as soon as the task changed. apache#74365 added a
version to the task endpoint, so the task is now read at the version the
instance ran. That costs a round trip on task instance routes, since the
version is not known until the instance arrives, and asking earlier would
fetch a task that has to be discarded.

The newsfragment was a documentation section rather than a release note, so it
is cut to what the release notes need and points at the docs for the rest.
Editing it trips `check-newsfragment-pr-number`, which expects any newsfragment
a PR touches to be named for that PR; renaming this one would credit the wrong
PR for the feature, so the check is skipped by label instead.
bbovenzi added a commit that referenced this pull request Oct 8, 2026
Several things shipped with the field-path scoping in #74278 that review
caught after it merged, plus two fixes that depend on work landing since.

The troubleshooting steps name `airflow plugins list`, which does not exist --
`plugins` takes no subcommand -- so anyone following them to find out why a
view is not scoped as expected gets an argparse error instead.

The operator section recommends leaving `operator` and `class_ref.class_name`
unqualified so each page reads its own record, which is right, but the
load-time check then reports the one the page lacks as a path that will make
the view "appear in more places than intended". That is untrue for this block:
the other path is what scopes this destination. Following the documentation
should not produce a warning saying the documentation is wrong. The check now
tells a path that names no field anywhere -- a misspelling -- apart from one
that names a real field on a record this destination does not have, and says
only what is true of each. The section leads with one view per destination,
which needs no such reasoning, and keeps the single block as the shorter form.

A path that matches no field at all now withholds the view instead of loading
it. The browser cannot tell a misspelling from a field this page's record
simply does not have -- a block shared across destinations relies on the
latter being skipped -- so it skips both, and skipping widens the scope. A
typo therefore showed the view everywhere, the opposite of what its author
asked for. The response models are in hand when plugins load, so the two are
distinguishable there: a field no record has cannot be anything but a mistake,
while one a sibling record has is the shared-block pattern and still loads. A
view that disappears gets noticed; one on every page looks deliberate.

Validation also edited the plugin author's own `applies_to` dictionary to drop
null values. Harmless in isolation, but a plugin may pass one dictionary to
several views, and rewriting it is not this code's to do.

Which record an unqualified path is rooted at is also decided twice: once when
plugins load, to choose what to validate, and again in the browser, to choose
what to match. Nothing at runtime notices when the two tables disagree -- a
destination only one of them knows about makes every path on it unevaluable,
which shows the view everywhere instead of scoping it, and would surface later
as someone else's bug. A prek check compares them, so that drift fails before
it merges.

Scoping a task-level view on `task.*` judged historical task instances by the
Dag's definition today, so a view scoped to an operator stopped appearing on
the runs that actually used it as soon as the task changed. #74365 added a
version to the task endpoint, so the task is now read at the version the
instance ran. That costs a round trip on task instance routes, since the
version is not known until the instance arrives, and asking earlier would
fetch a task that has to be discarded.

The newsfragment was a documentation section rather than a release note, so it
is cut to what the release notes need and points at the docs for the rest.
Editing it trips `check-newsfragment-pr-number`, which expects any newsfragment
a PR touches to be named for that PR; renaming this one would credit the wrong
PR for the feature, so the check is skipped by label instead.
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.

2 participants