Skip to content

LatestOnlyOperator not working if just before a Dynamic Task Mapping #62118

Closed

Description

@lcottereau

Apache Airflow version

Other Airflow 3 version (please specify below)

If "Other Airflow 3 version" selected, which one?

3.1.5

What happened?

When backfilling a DAG with LatestOnlyOperator, I realised the tasks after the LatestOnlyOperator were still executing.

I think it used to work before (probably in 2.*) but can't confirm that anymore.

What you think should happen instead?

When backfilling (before the current schedule), the tasks following the LatestOnlyOperator should be skipped, as per the purpose of this operator.

How to reproduce

The following stripped-down code reproduces the problem in my environment, when I backfill a few days before the current day:

  • for the test_bug_OK DAG, intermediate_step and print_all tasks are skipped
  • for the test_bug_KO DAG, print_all tasks still execute
from airflow.providers.standard.operators.latest_only import LatestOnlyOperator
from airflow.sdk import DAG, task
from pendulum import datetime

with DAG(
    dag_id="test_bug_KO",
    schedule="0 1 * * *",
    start_date=datetime(2026, 1, 1),
    catchup=False,
):
    is_latest = LatestOnlyOperator(task_id="is_latest")

    @task
    def print_label(label: str):
        print(label)

    print_all = print_label.expand(label=["Label 0", "Label 1"])

    is_latest >> print_all


with DAG(
    dag_id="test_bug_OK",
    schedule="0 1 * * *",
    start_date=datetime(2026, 1, 1),
    catchup=False,
):
    is_latest = LatestOnlyOperator(task_id="is_latest")

    @task
    def print_label(label: str):
        print(label)


    intermediate_step = print_label("Before")

    print_all = print_label.expand(label=["Label 0", "Label 1"])

    is_latest >> intermediate_step >> print_all

Operating System

Debian 13.3

Versions of Apache Airflow Providers

apache-airflow-providers-amazon==9.18.0
apache-airflow-providers-common-compat==1.10.0
apache-airflow-providers-common-io==1.7.0
apache-airflow-providers-common-sql==1.30.0
apache-airflow-providers-fab==3.0.1
apache-airflow-providers-http==5.6.0
apache-airflow-providers-postgres==6.5.0
apache-airflow-providers-samba==4.12.0
apache-airflow-providers-smtp==2.4.0
apache-airflow-providers-ssh==4.1.5
apache-airflow-providers-standard==1.10.0

Deployment

Virtualenv installation

Deployment details

No response

Anything else?

The problem recurs every time

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Activity

  1. tirkarthi commented on Feb 18, 2026

    @tirkarthi
    Contributor

    It seems when the LatestOnlyOperator is a not dynamic then map_index of -1 is passed to downstream tasks. In case of dynamic tasks being dependent on LatestOnlyOperator it will try to skip -1 which will not exist but in case of normal dependent then -1 will be correct and as it's marked skipped the downstream though dynamic is also marked as skipped.

    [2026-02-18 17:42:54] INFO - Checking latest only with left_window: 2026-01-03 01:00:00+00:00 right_window: 2026-01-05 01:00:00+00:00 now: 2026-02-18 12:12:54.160606+00:00
    [2026-02-18 17:42:54] INFO - Not latest execution, skipping downstream.
    [2026-02-18 17:42:54] INFO - Branch into []
    [2026-02-18 17:42:54] INFO - Following branch set()
    [2026-02-18 17:42:54] INFO - Skipping tasks [('print_label', -1)]
    

    skip_tasks = [
    (t.task_id, ti.map_index) for t in downstream_tasks if t.task_id not in branch_task_id_set
    ]
    follow_task_ids = [t.task_id for t in downstream_tasks if t.task_id in branch_task_id_set]
    log.info("Skipping tasks %s", skip_tasks)

  2. added a commit that references this issue on Feb 21, 2026
    dfe52b7
  3. added 2 commits that reference this issue on Mar 4, 2026
    3d3d76e
    d7e4707
  4. added a commit that references this issue on Mar 12, 2026
    41d897f
  5. added 2 commits that reference this issue on Mar 12, 2026
    115e169
    f4656c3
  6. added a commit that references this issue on Mar 12, 2026
    c066982
  7. added a commit that references this issue on Mar 12, 2026
    234690f
  8. added a commit that references this issue on Mar 13, 2026
    9ec05bb
  9. added a commit that references this issue on Mar 25, 2026
    bfe8450
  10. added a commit that references this issue on Aug 3, 2026
    1b650e6
  11. added a commit that references this issue on Sep 12, 2026
    ee5cf6a
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:corekind:bugThis is a clearly a bugneeds-triagelabel for new issues that we didn't triage yet

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions