Repository navigation
Description
Under which category would you file this issue?
Airflow Core
Apache Airflow version
3.3.0
What happened and how to reproduce it?
airflow db clean silently skips dag_run records where start_date IS NULL. These records accumulate indefinitely in the metadata database and can never be cleaned by any number of airflow db clean runs.
This affects any dag_run that is marked failed before execution begins .
In our production environment, this resulted in 11,841+ orphaned dag_run records that were permanently invisible to the cleanup command.
Root cause
In airflow-core/src/airflow/utils/db_cleanup.py, the _build_query() function builds the cleanup query with:
conditions = [base_table_recency_col < clean_before_timestamp]For dag_run, recency_column is start_date. When start_date IS NULL:
NULL < '2026-07-15'evaluates toNULLin SQL (notTRUE)- The row is silently excluded from the result set
- The row can never be deleted by
airflow db clean
How to reproduce
1. Create a simple test DAG with max_active_runs=1:
from airflow.sdk import DAG, task
from datetime import datetime, timedelta
import time
with DAG(
dag_id="test.null_start_date_repro",
schedule=None,
start_date=datetime(1970, 1, 1),
catchup=False,
max_active_runs=1,
) as dag:
@task
def wait_2_minutes():
time.sleep(120)
wait_2_minutes()
2. Trigger two runs:
- Trigger run 1 — it starts executing (sleeps 2 min),
start_dateis set - Trigger run 2 while run 1 is still running — it enters
queuedstate withstart_date = NULL(blocked bymax_active_runs=1) - Mark run 2 as
failedvia the UI while it's still queued
3. Verify the state in the database:
SELECT id, run_id, start_date, state, created_at
FROM dag_run
WHERE dag_id = 'test.null_start_date_repro'
ORDER BY created_at;
Result:
| id | run_id | start_date | state | created_at |
|---|---|---|---|---|
| 4334 | manual__...40.338513 | 2026-07-14 12:03:41 | success | 2026-07-14 12:03:40 |
| 4335 | manual__...45.960859 | NULL | failed | 2026-07-14 12:03:45 |
4. Run airflow db clean dry-run (with a future timestamp to ensure all records are eligible):
airflow db clean \
--clean-before-timestamp '2026-07-15 00:00:00+00:00' \
--tables 'dag_run' \
--dag-ids 'test.null_start_date_repro' \
--dry-run \
--verbose \
--yesOutput:
Performing dry run for table dag_run
Checking table dag_run
Found 1 rows meeting deletion criteria.
Expected: 2 rows found (both dag_runs)
Actual: Only 1 row found — the NULL start_date record (id=4335) is invisible
Impact
- NULL
start_daterecords accumulate indefinitely — no number of cleanup runs will remove them - In our production DB: 11,841 orphaned records from failed backfills (logical_date ranging from 1994 to 2026)
What you think should happen instead?
airflow db clean should be able to clean dag_run records regardless of whether start_date is NULL or not.
One approach to solve this:
- When
start_dateis NULL, the cleanup should fall back tocreated_at - This should be opt-in via a CLI flag (e.g.
--fallback-on-null)
Operating System
GKE / Linux (Debian-based Airflow container)
Deployment
Official Apache Airflow Helm Chart
Apache Airflow Provider(s)
No response
Versions of Apache Airflow Providers
No response
Official Helm Chart version
Not Applicable
Kubernetes Version
No response
Helm Chart configuration
No response
Docker Image customizations
No response
Anything else?
No response
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
boring-cyborg commentedon Jul 14, 2026
Thanks for opening your first issue here! Be sure to follow the issue template! If you are willing to raise PR to address this issue please do so, no need to wait for approval.
fix(db_cleanup): handle NULL start_date in dag_run cleanup