Skip to content

dag_version inflection when using TimeSensor with start_from_trigger = True #69543

Open

Description

@202201142

Under which category would you file this issue?

Providers

Apache Airflow version

3.2.2

What happened and how to reproduce it?

TimeSensor with start_from_trigger=True produces a different serialized DAG (new DAG version) on every DAG-file parse, even when nothing in the DAG file has changed.
Root cause: in TimeSensor.init, the target datetime is computed using datetime.datetime.now(self.dag.timezone):

aware_time = timezone.coerce_datetime(
    datetime.datetime.combine(
        datetime.datetime.now(self.dag.timezone), target_time, self.dag.timezone
    )
)
self.target_datetime = timezone.convert_to_utc(aware_time)
...
if self.start_from_trigger:
    self.start_trigger_args.trigger_kwargs = dict(
        moment=self.target_datetime, end_from_trigger=self.end_from_trigger
    )

init runs at DAG-parse time, not task-execution time, so datetime.now() is evaluated fresh on every parse cycle. The resulting target_datetime is written into start_trigger_args.trigger_kwargs, which is exactly the attribute the scheduler serializes to hand the task directly to the triggerer (the reason start_from_trigger exists at all). Since a volatile value is now part of the serialized operator, the serialized DAG hash changes on essentially every parse a new DAG version is created continuously on every dag_run.

Reproducable Example:

from __future__ import annotations

import datetime
import pendulum

from airflow.sdk import DAG
from airflow.providers.standard.sensors.time import TimeSensor

with DAG(
    dag_id="time_sensor_dag",
    schedule="@daily",
    start_date=pendulum.datetime(2026, 1, 1, tz="UTC"),
    catchup=False,
) as dag:
    wait = TimeSensor(
        task_id="wait_until_noon",
        target_time=datetime.time(12, 0, 0),
        start_from_trigger=True,
    )
  • Deploy this DAG with a triggerer running.
  • it will change its verstion every schduled dag_runs.

Also you can verify from serialized_dag table entry where its dag_hash changes because of that TimeSensor task trigger_start_kwargs changes.

What you think should happen instead?

The docstring for TimeSensor currently states: "Time will be evaluated against data_interval_end if present for the Dag run, otherwise run_after will be used."

implying the target moment should be derived from the DagRun, a runtime concept. The actual code instead uses parse-time datetime.now(), which has no relation to data_interval_end/run_after. Either the code should be fixed to match the documented (run-relative) behavior, or if its not possible then the docstring should be corrected to describe what actually happens with stating that dag_version will be changed.

Whatever the target-moment computation ends up being, it should not be baked into start_trigger_args.trigger_kwargs at init/parse time as an absolute value that changes on every parse. Compare with DateTimeSensorAsync, where target_time is a template_fields entry resolved via Jinja against the run context, and TimeDeltaSensor(Async), which doesn't implement start_from_trigger at all — presumably because its target (data_interval_end/run_after + delta) isn't knowable at parse time either. TimeSensor appears to be the one sensor that eagerly computes a volatile value instead of deferring it.

Operating System

Linux

Deployment

Docker-Compose

Apache Airflow Provider(s)

standard

Versions of Apache Airflow Providers

apache-airflow-providers-standard (main / current released version as of Airflow 3.2.2)

Official Helm Chart version

Not Applicable

Kubernetes Version

Not Applicable

Helm Chart configuration

Not Applicable

Docker Image customizations

Not Applicable

Anything else?

I'd love to help contribute — this would be my first PR.
I'll dig into this further and discuss before submitting a PR, since it touches DAG-serialization/versioning behavior. I'm willing to submit the fix, but I'd like guidance on the preferred direction: (a) derive the target moment from data_interval_end/run_after at trigger-start time instead of parse time, (b) some other approach, or (c) remove start_from_trigger from TimeSensor entirely.
I haven't looked at the triggerer's relevent code yet — I'll dig into it and come back with findings.

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Activity

  1. added
    kind:bug
    needs-triage
    on Jul 7, 2026
  2. uranusjr commented on Aug 11, 2026

    @uranusjr
    Member

    We have two Ps #69925 and #69746 that fix this in different ways. Please discuss the soluion in this issue first before continuing further work.

  3. RehanAhmad25 commented on Aug 13, 2026

    @RehanAhmad25
    Contributor

    We have two Ps #69925 and #69746 that fix this in different ways. Please discuss the soluion in this issue first before continuing further work.

    Since two PRs (#69746 and #69925) are fixing this differently, summarizing both here so the approach can be decided in one place.

    #69746 (TimeOfDayTrigger) keeps start_from_trigger working. It found and fixed an additional real bug along the way: start_trigger_args is a class-level attribute, and the original code mutated it directly, so multiple TimeSensor instances could end up sharing the same (wrong) moment. The fix stores parse-stable data and resolves the concrete UTC moment lazily when the trigger starts. Cost: a new trigger class plus DST edge-case handling (spring-forward gaps, fall-back ambiguity).

    #69925 deprecates start_from_trigger for TimeSensor entirely: it's now a property that always reads False, with a setter that emits a deprecation warning on any assignment (at construction or afterward). target_datetime becomes a recomputed property instead of a stale parse-time value. Simpler diff, but drops a working, documented capability, anyone currently relying on start_from_trigger=True to skip a worker slot loses that on upgrade.

    Both fix the churn. The real question is whether the worker-slot optimization start_from_trigger provides is worth the added complexity of lazy resolution + DST handling to preserve, versus removing it outright. Would appreciate maintainer input on which direction to commit to so we're not duplicating review effort across two PRs.

  4. uranusjr commented on Aug 17, 2026

    @uranusjr
    Member

    I feel it may be suboptimal to drop the feature entirely (start_from_trigger is fixed at False) since it seems like we can fix the original issue. Honestly I don’t use it so it’s fine for me personally either way, but framing it as a fix is somewhat underselling the impact from a maintainer perspective.

    The patch we currently have (#69746) is also not in a very good state right now, so it is technically still not completely clear whether the fix can actually work. But regardless, I would prefer if someone can try to fix the underlying feature first before coming around to the decision whether to actually keep it at all.

  5. RehanAhmad25 commented on Aug 17, 2026

    @RehanAhmad25
    Contributor

    Makes sense, I'll rework it properly this time rather than patch further on top of what's in PR : #69925. I'll build it fresh from ground zero in a new PR: start_trigger_args built per-instance instead of mutating the class attribute, and the moment resolved lazily at trigger-start time instead of parse time, so start_from_trigger actually keeps working. I'd rather not clutter PR : #69925 with a different design mid-review, so I'll link the new PR back here once it's up, and we can close this one out depending on how that lands.

  6. Vamsi-klu commented on Aug 29, 2026

    @Vamsi-klu
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

    area:providerskind:bugneeds-triageprovider:standard

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions