Repository navigation
Description
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_OKDAG,intermediate_stepandprint_alltasks are skipped - for the
test_bug_KODAG,print_alltasks 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_allOperating 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
- I agree to follow this project's Code of Conduct
Activity
tirkarthi commentedon Feb 18, 2026
It seems when the
LatestOnlyOperatoris a not dynamic then map_index of -1 is passed to downstream tasks. In case of dynamic tasks being dependent onLatestOnlyOperatorit will try to skip-1which will not exist but in case of normal dependent then-1will be correct and as it's marked skipped the downstream though dynamic is also marked as skipped.airflow/providers/standard/src/airflow/providers/standard/utils/skipmixin.py
Lines 180 to 185 in 0d3a034
fix: use parent's map_index for XCom lookup in NotPreviouslySkippedDep
fix: use parent's map_index for XCom lookup in NotPreviouslySkippedDep
fix: use parent's map_index for XCom lookup in NotPreviouslySkippedDep
fix: `LatestOnlyOperator` not working if direct upstream of Dynamic T…
[v3-1-test] fix: `LatestOnlyOperator` not working if direct upstream …
[v3-1-test] fix: `LatestOnlyOperator` not working if direct upstream …
fix: `LatestOnlyOperator` not working if direct upstream of Dynamic T…
[v3-1-test] fix: `LatestOnlyOperator` not working if direct upstream …
fix: `LatestOnlyOperator` not working if direct upstream of Dynamic T…
[v3-1-test] fix: `LatestOnlyOperator` not working if direct upstream …
fix: `LatestOnlyOperator` not working if direct upstream of Dynamic T…
fix: `LatestOnlyOperator` not working if direct upstream of Dynamic T…