You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "bileyroy (via GitHub)" <gi...@apache.org> on 2026/07/14 16:23:24 UTC
[PR] fix(db_cleanup): handle NULL start_date in dag_run cleanup [airflow]
bileyroy opened a new pull request, #69879:
URL: https://github.com/apache/airflow/pull/69879
closes: #69872
When `start_date` is `NULL` (e.g. dag_runs that were marked failed before execution began), the cleanup query's `WHERE start_date < cutoff` evaluates to `NULL` and silently skips these rows forever.
## Changes
- Add `fallback_recency_column_name` field to `_TableConfig` (set to `created_at` for `dag_run`)
- Add `--fallback-cleanup-on-null` CLI flag (opt-in, off by default)
- When enabled, the main WHERE condition uses `COALESCE(start_date, created_at) < cutoff`
- Add 3 unit tests covering the flag behavior
## Test plan
- [x] `pytest airflow-core/tests/unit/utils/test_db_cleanup.py -xvs` — 70 passed
- [x] `ruff check` / `ruff format` — clean
- [x] `mypy` — clean
- [x] Manual testing in local via `airflow standalone`: 3 dag_runs (success, failed+NULL, queued+NULL), verified dry-run count changes from 1→3 with flag
<img width="1607" height="796" alt="image" src="https://github.com/user-attachments/assets/e93641bc-d93e-45d0-829d-2c7748f2fdcf" />
<img width="1607" height="643" alt="image" src="https://github.com/user-attachments/assets/ba213f21-5d93-4d83-9032-2b4c7d215218" />
<img width="1607" height="641" alt="image" src="https://github.com/user-attachments/assets/004ac8cf-254f-47d0-8915-ddf5d11efda9" />
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix `airflow db clean` skipping dag_run records with NULL start_date [airflow]
Posted by "bileyroy (via GitHub)" <gi...@apache.org>.
bileyroy commented on code in PR #69879:
URL: https://github.com/apache/airflow/pull/69879#discussion_r3689001606
##########
airflow-core/src/airflow/utils/db_cleanup.py:
##########
@@ -490,6 +517,8 @@ def _cleanup_table(
extra_filters: list[Any] | None = None,
skip_if_referenced: list[tuple[str, str]] | None = None,
referenced_pk_column: str = "id",
+ fallback_recency_column=None,
Review Comment:
@bugraoz93 can you confirm please?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(db_cleanup): handle NULL start_date in dag_run cleanup [airflow]
Posted by "bileyroy (via GitHub)" <gi...@apache.org>.
bileyroy commented on code in PR #69879:
URL: https://github.com/apache/airflow/pull/69879#discussion_r3596603841
##########
airflow-core/src/airflow/utils/db_cleanup.py:
##########
@@ -490,6 +517,8 @@ def _cleanup_table(
extra_filters: list[Any] | None = None,
skip_if_referenced: list[tuple[str, str]] | None = None,
referenced_pk_column: str = "id",
+ fallback_recency_column=None,
Review Comment:
@bugraoz93 so this `fallback_recency_column` is part of `_TableConfig` ([here](https://github.com/apache/airflow/pull/69879/changes#diff-0f691d24c54a28756110b2d9125bb06a3d8862333977ef86ec30ad33220440c8R162)) and is derived in `__post_init__` (same pattern as `recency_column` which is also derived there from `recency_column_name`). It is not passed explicitly, but coming from `**table_config.__dict__` [here](https://github.com/apache/airflow/pull/69879/changes#diff-0f691d24c54a28756110b2d9125bb06a3d8862333977ef86ec30ad33220440c8R763).
Computing it inside `_cleanup_table()` would be redundant since `__post_init__` already does this derivation once at config initialization time.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(db_cleanup): handle NULL start_date in dag_run cleanup [airflow]
Posted by "bugraoz93 (via GitHub)" <gi...@apache.org>.
bugraoz93 commented on code in PR #69879:
URL: https://github.com/apache/airflow/pull/69879#discussion_r3588766962
##########
airflow-core/src/airflow/utils/db_cleanup.py:
##########
@@ -490,6 +517,8 @@ def _cleanup_table(
extra_filters: list[Any] | None = None,
skip_if_referenced: list[tuple[str, str]] | None = None,
referenced_pk_column: str = "id",
+ fallback_recency_column=None,
Review Comment:
This has been never passed from the caller. I see the enitre logic coupled with this field and the boolean asked to user. If you check below comment where it called, you will see we only pass the user input one.
Even this is calculated in inner parts, it should only exists where it is needed and calculated.
##########
airflow-core/src/airflow/utils/db_cleanup.py:
##########
@@ -728,6 +764,7 @@ def run_cleanup(
skip_archive=skip_archive,
session=session,
batch_size=batch_size,
+ fallback_cleanup_on_null=fallback_cleanup_on_null,
Review Comment:
Here we are not pssing the other new recency one
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix `airflow db clean` skipping dag_run records with NULL start_date [airflow]
Posted by "uranusjr (via GitHub)" <gi...@apache.org>.
uranusjr commented on code in PR #69879:
URL: https://github.com/apache/airflow/pull/69879#discussion_r3763805743
##########
airflow-core/src/airflow/utils/db_cleanup.py:
##########
@@ -154,11 +163,12 @@ def readable_config(self):
table_name="dag_run",
recency_column_name="start_date",
dag_id_column_name="dag_id",
- extra_columns=["dag_id", "run_type"],
+ extra_columns=["dag_id", "run_type", "created_at"],
Review Comment:
Since created_at was only added in 3.2.0, we probably need more columns for this. Otherwise the oldest dag runs will never be able to be selected by the query, which is the opposite of what we want.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix `airflow db clean` skipping dag_run records with NULL start_date [airflow]
Posted by "github-actions[bot] (via GitHub) via commits" <co...@airflow.apache.org>.
github-actions[bot] closed pull request #69879: Fix `airflow db clean` skipping dag_run records with NULL start_date
URL: https://github.com/apache/airflow/pull/69879
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(db_cleanup): handle NULL start_date in dag_run cleanup [airflow]
Posted by "boring-cyborg[bot] (via GitHub)" <gi...@apache.org>.
boring-cyborg[bot] commented on PR #69879:
URL: https://github.com/apache/airflow/pull/69879#issuecomment-4971490940
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](https://github.com/apache/airflow/blob/main/contributing-docs/README.rst)
Here are some useful points:
- Pay attention to the quality of your code (ruff, mypy and type annotations). Our [prek-hooks]( https://github.com/apache/airflow/blob/main/contributing-docs/08_static_code_checks.rst#prerequisites-for-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](https://github.com/apache/airflow/blob/main/airflow-core/docs/howto/custom-operator.rst) Consider adding an example Dag that shows how users should use it.
- Consider using [Breeze environment](https://github.com/apache/airflow/blob/main/dev/breeze/doc/README.rst) 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](https://www.apache.org/foundation/policies/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]( https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#coding-style-and-best-practices).
- 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
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix `airflow db clean` skipping dag_run records with NULL start_date [airflow]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #69879:
URL: https://github.com/apache/airflow/pull/69879#issuecomment-6457234248
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 5 days if no further activity occurs. Thank you for your contributions.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(db_cleanup): handle NULL start_date in dag_run cleanup [airflow]
Posted by "bileyroy (via GitHub)" <gi...@apache.org>.
bileyroy commented on code in PR #69879:
URL: https://github.com/apache/airflow/pull/69879#discussion_r3596603841
##########
airflow-core/src/airflow/utils/db_cleanup.py:
##########
@@ -490,6 +517,8 @@ def _cleanup_table(
extra_filters: list[Any] | None = None,
skip_if_referenced: list[tuple[str, str]] | None = None,
referenced_pk_column: str = "id",
+ fallback_recency_column=None,
Review Comment:
@bugraoz93 so this `fallback_recency_column` is part of `_TableConfig` ([here](https://github.com/apache/airflow/pull/69879/changes#diff-0f691d24c54a28756110b2d9125bb06a3d8862333977ef86ec30ad33220440c8R162)) and is derived in `__post_init__` (same pattern as `recency_column` which is also derived there from `recency_column_name`). It is not passed explicitly, but coming from `**table_config.__dict__` [here](https://github.com/apache/airflow/pull/69879/changes#diff-0f691d24c54a28756110b2d9125bb06a3d8862333977ef86ec30ad33220440c8R763) in the usage of `_cleanup_table()`
Computing it inside `_cleanup_table()` would be redundant since `__post_init__` already does this derivation once at config initialization time.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(db_cleanup): handle NULL start_date in dag_run cleanup [airflow]
Posted by "bileyroy (via GitHub)" <gi...@apache.org>.
bileyroy commented on code in PR #69879:
URL: https://github.com/apache/airflow/pull/69879#discussion_r3596622150
##########
airflow-core/src/airflow/utils/db_cleanup.py:
##########
@@ -728,6 +764,7 @@ def run_cleanup(
skip_archive=skip_archive,
session=session,
batch_size=batch_size,
+ fallback_cleanup_on_null=fallback_cleanup_on_null,
Review Comment:
Addressed above.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(db_cleanup): handle NULL start_date in dag_run cleanup [airflow]
Posted by "bugraoz93 (via GitHub)" <gi...@apache.org>.
bugraoz93 commented on PR #69879:
URL: https://github.com/apache/airflow/pull/69879#issuecomment-4982585316
Thanks for your first PR!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(db_cleanup): handle NULL start_date in dag_run cleanup [airflow]
Posted by "bileyroy (via GitHub)" <gi...@apache.org>.
bileyroy commented on code in PR #69879:
URL: https://github.com/apache/airflow/pull/69879#discussion_r3596603841
##########
airflow-core/src/airflow/utils/db_cleanup.py:
##########
@@ -490,6 +517,8 @@ def _cleanup_table(
extra_filters: list[Any] | None = None,
skip_if_referenced: list[tuple[str, str]] | None = None,
referenced_pk_column: str = "id",
+ fallback_recency_column=None,
Review Comment:
@bugraoz93 so this `fallback_recency_column` is part of `_TableConfig` ([here](https://github.com/apache/airflow/pull/69879/changes#diff-0f691d24c54a28756110b2d9125bb06a3d8862333977ef86ec30ad33220440c8R162)) and is derived in `__post_init__` (same pattern as `recency_column` which is also derived there from `recency_column_name`). It is not passed explicitly, but coming from `**table_config.__dict__` [here](https://github.com/apache/airflow/pull/69879/changes#diff-0f691d24c54a28756110b2d9125bb06a3d8862333977ef86ec30ad33220440c8R763) in the usage of `_cleanup_table()` function call
Computing it inside `_cleanup_table()` would be redundant since `__post_init__` already does this derivation once at config initialization time.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add fallback cleanup for NULL start_date in airflow db clean command [airflow]
Posted by "bileyroy (via GitHub)" <gi...@apache.org>.
bileyroy commented on code in PR #69879:
URL: https://github.com/apache/airflow/pull/69879#discussion_r3608512282
##########
airflow-core/src/airflow/utils/db_cleanup.py:
##########
@@ -490,6 +517,8 @@ def _cleanup_table(
extra_filters: list[Any] | None = None,
skip_if_referenced: list[tuple[str, str]] | None = None,
referenced_pk_column: str = "id",
+ fallback_recency_column=None,
Review Comment:
@bugraoz93 does it sound good?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org