Skip to content

Fix Triggerer subprocess sys.path gap for DAG bundle helpers#65887

Open
gaurav0107 wants to merge 1 commit intoapache:mainfrom
gaurav0107:fix/65455-triggerer-subprocess-cannot-import-helpe
Open

Fix Triggerer subprocess sys.path gap for DAG bundle helpers#65887
gaurav0107 wants to merge 1 commit intoapache:mainfrom
gaurav0107:fix/65455-triggerer-subprocess-cannot-import-helpe

Conversation

@gaurav0107
Copy link
Copy Markdown
Contributor

TriggerRunner.create_triggers() now initializes the active DAG bundle and appends its root to sys.path before importing trigger classes, matching the pattern established for the task runner, callback supervisor, DAG processor, and CLI in #55894. Triggers whose classpath points into dags/ (e.g. helpers.emr_sensor_helpers.MyTrigger) no longer raise ModuleNotFoundError at deserialization.

Changes

  1. airflow-core/src/airflow/executors/workloads/trigger.py — add optional bundle_info: BundleInfo | None = None field to the RunTrigger workload. Optional because asset-based triggers have no associated bundle.
  2. airflow-core/src/airflow/jobs/triggerer_job_runner.py:
    • TriggerRunner._create_workload: resolve BundleInfo(name=..., version=...) from serialized_dag_model.dag_version and plumb it into both non-asset RunTrigger(...) construction sites. Asset-based branch keeps bundle_info=None — asset triggers ship as provider-installed classes, not bundle-local helpers.
    • New TriggerRunner._ensure_bundle_on_syspath helper mirroring callback_supervisor.py: if a bundle is specified, initialize it via DagBundlesManager().get_bundle(...) and append str(bundle.path) to sys.path (deduped via self._bundle_paths_added). Failures log warning with exc_info but do not crash the triggerer — same defensiveness as the callback supervisor.
    • TriggerRunner.create_triggers: call _ensure_bundle_on_syspath(workload.bundle_info) immediately before get_trigger_by_classpath(workload.classpath).
  3. airflow-core/tests/unit/jobs/test_triggerer_job.py — three new unit tests covering the dedup path (appends once), the no-op paths (None, empty name, DagBundlesManager never instantiated), and the exception path (swallowed, sys.path unchanged). Each test restores sys.path in a try/finally to avoid cross-test contamination.

closes: #65455


Was generative AI tooling used to co-author this PR?
  • Yes — Claude Opus 4.7 (1M context)

Generated-by: Claude Opus 4.7 (1M context) following the guidelines

TriggerRunner.create_triggers() now initializes the active DAG bundle
and appends its root to sys.path before importing trigger classes,
matching the pattern established for the task runner, callback
supervisor, DAG processor, and CLI in apache#55894. Triggers whose classpath
points into dags/ no longer raise ModuleNotFoundError at
deserialization.

closes: apache#65455
@boring-cyborg boring-cyborg Bot added area:Executors-core LocalExecutor & SequentialExecutor area:Triggerer labels Apr 26, 2026
@gaurav0107 gaurav0107 marked this pull request as ready for review April 26, 2026 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Executors-core LocalExecutor & SequentialExecutor area:Triggerer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Triggerer subprocess cannot import helpers from DAG bundle root (sys.path gap)

1 participant