Skip to content

TimeSensor triggers immediately when used over midnight (UTC) #9609

@freget

Description

@freget

Apache Airflow version: 1.10.10 (issue exists in current master as well)

Environment: does not seem relevant

What happened:

The TimeSensor does trigger if the current time is later than the defined trigger time. Looking at the source code, the trigger rule is defined as

return timezone.utcnow().time() > self.target_time

This leads to problems when the DAG runs over midnight UTC. For example, suppose the following DAG:

with DAG('foo', 
    default_args={'start_date': datetime(2020, 7, 1, tzinfo=pendulum.timezone("Europe/Berlin"))}, 
    schedule_interval="0 0 * * *") as dag:

    # in summer, Europe/Berlin is two hours after UTC, hence: 
    time_04h00_local = TimeSensor(task_id="time_01h30", target_time=time(hour=2, minute=00))

This DAG will be triggered at 22:00 UTC. Then, according to the trigger rule:

22:00 UTC > 2:00 UTC

Hence, the TimeSensor will be triggered immediately.

What you expected to happen:

The TimeSensor should trigger at the following day if target_time < next_execution_date.time()

Possible workarounds:

One can always use the TimeDeltaSensor to archive similar effects. This does result in code that is not as readable, though.

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind:bugThis is a clearly a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions