From 3d11495d4d532eaa56c78bc5c9f4abd88d2f5a8f Mon Sep 17 00:00:00 2001 From: Radu Date: Thu, 19 Dec 2024 13:19:59 +0100 Subject: [PATCH 1/2] use dag_folder for stats --- airflow/models/dagbag.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/airflow/models/dagbag.py b/airflow/models/dagbag.py index 03e416c2478b8..ebb810529f9ee 100644 --- a/airflow/models/dagbag.py +++ b/airflow/models/dagbag.py @@ -580,7 +580,7 @@ def collect_dags( file_parse_end_dttm = timezone.utcnow() stats.append( FileLoadStat( - file=filepath.replace(settings.DAGS_FOLDER, ""), + file=filepath.replace(str(dag_folder), ""), duration=file_parse_end_dttm - file_parse_start_dttm, dag_num=len(found_dags), task_num=sum(len(dag.tasks) for dag in found_dags), From 80bc2f9547e5923344636244316e7c4937f92d18 Mon Sep 17 00:00:00 2001 From: Radu Date: Thu, 19 Dec 2024 20:25:40 +0100 Subject: [PATCH 2/2] add test --- tests/models/test_dagbag.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/models/test_dagbag.py b/tests/models/test_dagbag.py index f8cbc4d3e6632..8b71ea4244092 100644 --- a/tests/models/test_dagbag.py +++ b/tests/models/test_dagbag.py @@ -848,6 +848,13 @@ def test_dagbag_dag_collection(self): dagbag = DagBag(dag_folder=TEST_DAGS_FOLDER, include_examples=False) assert dagbag.dags + def test_dagbag_collect_dags_stats_have_filepath_without_dag_folder(self): + with conf_vars({("core", "DAGS_FOLDER"): "/different/path"}): + dagbag = DagBag(dag_folder=TEST_DAGS_FOLDER, include_examples=False) + + assert dagbag.dagbag_stats + assert str(TEST_DAGS_FOLDER) not in dagbag.dagbag_stats[0].file + def test_dabgag_captured_warnings(self): dag_file = os.path.join(TEST_DAGS_FOLDER, "test_dag_warnings.py") dagbag = DagBag(dag_folder=dag_file, include_examples=False, collect_dags=False)