Skip to content

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

Closed

Description

@hkc-8010

Summary

TriggerRunner.get_trigger_by_classpath() calls importlib.import_module() against an unmodified sys.path that never includes the active DAG bundle root (e.g., dags/). This means any trigger that imports a helper module stored inside the bundle fails with ModuleNotFoundError at deserialization time.

PR #55894 fixed this gap for the DagBag parsing path, the worker (task runner), the DAG processor, and the CLI — but the Triggerer subprocess was missed entirely.

Affected version(s)

Airflow 3.x (3.1.x, 3.2+). Airflow 2.x is not affected because DAG bundles are a 3.x concept.

What happened

A trigger whose serialize() return value includes a classpath pointing into dags/ (e.g., helpers.emr_sensor_helpers.MyTrigger) raises:

ModuleNotFoundError: No module named 'helpers'

in the Triggerer subprocess even after PR #55894 landed (Airflow 3.1.7 / 3.1.8), because the triggerer process never adds the bundle root to sys.path.

Root cause (code path)

TriggerRunnerSupervisor._create_workload()
  → workloads.RunTrigger(classpath=..., ...)   # no bundle_info field

TriggerRunnerSupervisor → subprocess: messages.StartTriggerer()  # no bundle info

TriggerRunner.create_triggers()
  → self.get_trigger_by_classpath(workload.classpath)
    → import_string(classpath)
      → importlib.import_module(...)   # sys.path has no bundle root → ModuleNotFoundError

Key files:

  • airflow-core/src/airflow/jobs/triggerer_job_runner.py — TriggerRunner.get_trigger_by_classpath() (line ~1346), create_triggers() (line ~1081), _create_workload() (line ~672)
  • airflow-core/src/airflow/executors/workloads/trigger.py — RunTrigger has no bundle_info field

What the task runner already does (correct pattern)

ExecuteTask (the task workload) carries a BundleInfo field. The task runner subprocess receives it in StartupDetails, calls DagBundlesManager().get_bundle(...), calls bundle.initialize(), and appends the path to sys.path before executing user code.

The Triggerer needs the same treatment.

Proposed fix

  1. Add bundle_info: BundleInfo | None = None to RunTrigger workload (mirrors BaseDagBundleWorkload pattern).
  2. Populate it in TriggerRunnerSupervisor._create_workload() from trigger.task_instance.dag_model.bundle_name / trigger.task_instance.dag_run.bundle_version when a task_instance is present. Asset-based triggers (no task_instance) leave it None.
  3. Add TriggerRunner._ensure_bundle_on_syspath(bundle_info) that calls DagBundlesManager().get_bundle(...), bundle.initialize(), and appends the path to sys.path (with deduplication), mirroring the callback-supervisor pattern in task-sdk/src/airflow/sdk/execution_time/supervisor.py:~167.
  4. Call _ensure_bundle_on_syspath in create_triggers() before get_trigger_by_classpath().

Impact

Any Airflow 3.x deployment where trigger classes import helper modules stored inside dags/ is affected. This is particularly acute for Astro dags-only deploys, where helpers cannot be moved to include/ without requiring a full image rebuild on every code change — eliminating the main benefit of the dags-only deploy workflow.

Activity

  1. added a commit that references this issue on Apr 18, 2026
    75fc235
  2. added
    affected_version:3.2
    on Apr 19, 2026
  3. hkc-8010 commented on May 18, 2026

    @hkc-8010
    ContributorAuthor

    Closing this as wontfix.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    affected_version:3.2area:Triggererarea:corekind:bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions