Skip to content

LatestOnlyOperator fails in airflow-providers-standard >=1.1.0 #50911

@Limess

Description

@Limess

Apache Airflow Provider(s)

standard

Versions of Apache Airflow Providers

apache-airflow-providers-standard==1.1.0

Apache Airflow version

2.10.5, 2.11.0

Operating System

Airflow docker

Deployment

Other Docker-based deployment

Deployment details

Airflow base docker image with minor customisations on EKS

What happened

When upgrading airflow-providers-standard to from 1.0.0 to 1.1.0 or 1.2.0 we receive the following failure + stacktrace at runtime

[2025-05-21, 16:35:42 BST] {taskinstance.py:3313} ERROR - Task failed with exception
Traceback (most recent call last):
  File "/home/airflow/.local/lib/python3.12/site-packages/airflow/models/taskinstance.py", line 768, in _execute_task
    result = _execute_callable(context=context, **execute_callable_kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/airflow/.local/lib/python3.12/site-packages/airflow/models/taskinstance.py", line 734, in _execute_callable
    return ExecutionCallableRunner(
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/airflow/.local/lib/python3.12/site-packages/airflow/utils/operator_helpers.py", line 252, in run
    return self.func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/airflow/.local/lib/python3.12/site-packages/airflow/models/baseoperator.py", line 424, in wrapper
    return func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/airflow/.local/lib/python3.12/site-packages/airflow/providers/standard/operators/branch.py", line 105, in execute
    return self.do_branch(context, self.choose_branch(context))
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/airflow/.local/lib/python3.12/site-packages/airflow/providers/standard/operators/latest_only.py", line 69, in choose_branch
    dates = self._get_compare_dates(dag_run)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/airflow/.local/lib/python3.12/site-packages/airflow/providers/standard/operators/latest_only.py", line 110, in _get_compare_dates
    if prev_info := self.dag.timetable.next_dagrun_info(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/airflow/.local/lib/python3.12/site-packages/airflow/timetables/interval.py", line 105, in next_dagrun_info
    align_last_data_interval_end = self._align_to_prev(last_automated_data_interval.end)
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/airflow/.local/lib/python3.12/site-packages/airflow/timetables/_cron.py", line 145, in _align_to_prev
    prev_time = self._get_prev(current)
                ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/airflow/.local/lib/python3.12/site-packages/airflow/timetables/_cron.py", line 124, in _get_prev
    return convert_to_utc(current.in_timezone(self._timezone) - delta)
                          ^^^^^^^^^^^^^^^^^^^
AttributeError: 'datetime.datetime' object has no attribute 'in_timezone'. Did you mean: 'astimezone'?

The dag definition has the following parameters:

        {
            "start_date": datetime(2019, 9, 1),
            "retries": 2,
            "retry_delay": timedelta(minutes=5),
            "catchup": False,
            "max_active_tasks": 1,
            "default_args": default_args,
            "max_active_runs": 1,
            "schedule": "@hourly",
            "tags": [
                "analytics-ingest",
                "postgres-ingest",
                *dag_options.get("tags", []),
            ],
        },

What you think should happen instead

No error should occur

How to reproduce

Due to the simplicity of the DAG I'm inclined to say this occurs on any airflow 2.10.5/2.11.0 installation using airflow-providers-standard==1.2.0 where schedule="@hourly" and LatestOnlyOperator is used,

e.g.

from airflow.providers.standard.operators.latest_only import LatestOnlyOperator

LatestOnlyOperator(task_id="only_run_latest_execution")

Anything else

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions