Skip to content

Commit 978fda5

Browse files
authored
[Cloud Composer] Update maintenance DAG - DagRun additional filter (#13307)
* Adding missing filter of Externally Triggered DagRuns when cleaning Airflow metadata database. * Remove blank line - lint. * Update removing manual executions. We dont want to skip them. * Adding a comment as to what we are removing/ * Rewrite comments. * Skip nox for Python3.13 as it is not suported by AF. ;
1 parent 1d1e869 commit 978fda5

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

composer/workflows/airflow_db_cleanup.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,10 +338,12 @@ def build_query(
338338
query = query.filter(airflow_db_model.dag_id == dag_id)
339339

340340
if airflow_db_model == DagRun:
341-
# For DaRus we want to leave last DagRun regardless of its age
341+
# For DagRuns we want to leave last *scheduled* DagRun
342+
# regardless of its age
342343
newest_dagrun = (
343344
session
344345
.query(airflow_db_model)
346+
.filter(DagRun.external_trigger.is_(False))
345347
.filter(airflow_db_model.dag_id == dag_id)
346348
.order_by(desc(airflow_db_model.execution_date))
347349
.first()
@@ -350,7 +352,6 @@ def build_query(
350352
if newest_dagrun is not None:
351353
query = (
352354
query
353-
.filter(DagRun.external_trigger.is_(False))
354355
.filter(age_check_column <= max_date)
355356
.filter(airflow_db_model.id != newest_dagrun.id)
356357
)

composer/workflows/noxfile_config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"3.9",
3939
"3.10",
4040
"3.12",
41+
"3.13",
4142
], # Composer w/ Airflow 2 only supports Python 3.8
4243
# Old samples are opted out of enforcing Python type hints
4344
# All new samples should feature them

0 commit comments

Comments
 (0)