Skip to content

Populate trigger team_name at creation time for multi-team support#67605

Open
ramitkataria wants to merge 1 commit into
apache:mainfrom
aws-mwaa:ramitkataria/mt/populate-triggers
Open

Populate trigger team_name at creation time for multi-team support#67605
ramitkataria wants to merge 1 commit into
apache:mainfrom
aws-mwaa:ramitkataria/mt/populate-triggers

Conversation

@ramitkataria
Copy link
Copy Markdown
Contributor

@ramitkataria ramitkataria commented May 27, 2026

Populate trigger.team_name at all 4 trigger creation paths so that team-scoped triggerers can filter to their own team's triggers:

  • TaskInstance.defer_task() — resolves via DagModel.get_team_name(dag_id)
  • Execution API PATCH .../state (deferred) — resolves via get_team_name_for_ti(ti_id)
  • TriggererCallback.queue() — resolves via DagBundleModel.get_team_name(bundle_name)
  • Asset watcher triggers (bulk_write_to_db) — resolves via DagBundleModel.get_team_name(bundle_name)

All paths are gated on core.multi_team; when disabled, no DB query is executed and team_name remains NULL.

To support the above changes:

  • Add DagBundleModel.get_team_name() following the existing pattern used by Pool, Connection, Variable, and DagModel.
  • Add session parameter to Callback.queue() so triggerer callbacks can resolve team.

Was generative AI tooling used to co-author this PR?
  • Yes (Claude Code - Opus 4.6)

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

Populate `trigger.team_name` at all 4 trigger creation paths so that
team-scoped triggerers can filter to their own team's triggers:
- **`TaskInstance.defer_task()`** — resolves via `DagModel.get_team_name(dag_id)`
- **Execution API `PATCH .../state` (deferred)** — resolves via `get_team_name_for_ti(ti_id)`
- **`TriggererCallback.queue()`** — resolves via `DagBundleModel.get_team_name(bundle_name)`
- **Asset watcher triggers (`bulk_write_to_db`)** — resolves via `DagBundleModel.get_team_name(bundle_name)`

All paths are gated on `core.multi_team`; when disabled, no DB query
is executed and `team_name` remains NULL.

To support the above changes:
- Add `DagBundleModel.get_team_name()` following the existing pattern
used by Pool, Connection, Variable, and DagModel.
- Add `session` parameter to `Callback.queue()` so triggerer callbacks
can resolve team.
"next_method": "execute_callback",
}

with conf_vars({("core", "multi_team"): multi_team_enabled}):
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.

nit: move it as decorator of the test, that makes the test smaller (that applies to other location in your PR as well)


@staticmethod
@provide_session
def get_team_name(bundle_name: str, *, session: Session = NEW_SESSION) -> str | None:
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.

Please have unit test associated to this method

self.trigger_timeout = None

team_name: str | None = None
if conf.getboolean("core", "multi_team"):
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.

This is not covered by unit test

Copy link
Copy Markdown
Contributor

@o-nikolas o-nikolas left a comment

Choose a reason for hiding this comment

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

Other than Vincent's comments, this looks good to me

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants