Skip to content

Fix dags next-execution --table crash when no next schedule exists#67417

Open
vincere-mori wants to merge 1 commit into
apache:mainfrom
vincere-mori:fix-dag-next-execution-table-none-crash
Open

Fix dags next-execution --table crash when no next schedule exists#67417
vincere-mori wants to merge 1 commit into
apache:mainfrom
vincere-mori:fix-dag-next-execution-table-none-crash

Conversation

@vincere-mori
Copy link
Copy Markdown

Summary

airflow dags next-execution <dag_id> --table crashes with AttributeError when the DAG has no next scheduled run (e.g. schedule=None, or an @once DAG after its run, or --num-executions exceeds available runs).

The root cause is in the table-output branch:

# Before (buggy)
AirflowConsole().print_as_table([{n: f(o) for n, f in getters} for o in iter_next_dagrun_info()])

iter_next_dagrun_info() yields DagRunInfo | None. When o is None, calling operator.attrgetter(c)(None) raises AttributeError: 'NoneType' object has no attribute 'logical_date'.

The non-table path already handles None correctly:

for info in iter_next_dagrun_info():
    if info is None:
        print("[WARN] No following schedule can be found. ...", file=sys.stderr)
        ...

Reproduce

# no_schedule_dag.py
from airflow import DAG
from pendulum import datetime

with DAG("no_schedule", start_date=datetime(2025, 1, 1, tz="UTC"), schedule=None):
    pass
airflow dags next-execution no_schedule --table
# AttributeError: 'NoneType' object has no attribute 'logical_date'

Fix

Mirror the non-table None guard in the table path: skip None items and print the same warning to stderr.

Fixes #67394

The `--table` path passed all items from `iter_next_dagrun_info()`
directly into a list comprehension that calls `operator.attrgetter(c)`
on each item. When there is no next scheduled run (schedule=None, or
@once after its run, or more executions requested than the schedule
provides), the iterator yields `None`. Calling `attrgetter` on `None`
raises `AttributeError: 'NoneType' object has no attribute '...'`.

The non-table path already handled `None` correctly by printing a warning
to stderr and skipping to the next iteration. Apply the same guard to the
table path: skip `None` items and print the same warning message.

Fixes apache#67394
@boring-cyborg
Copy link
Copy Markdown

boring-cyborg Bot commented May 24, 2026

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide
Here are some useful points:

  • Pay attention to the quality of your code (ruff, mypy and type annotations). Our prek-hooks will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example Dag that shows how users should use it.
  • Consider using Breeze environment for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
  • Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: dev@airflow.apache.org
    Slack: https://s.apache.org/airflow-slack

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

airflow dags next-execution --table crashes when no next run exists

1 participant