Repository navigation
Description
Apache Airflow version
3.0.2
If "Other Airflow 2 version" selected, which one?
No response
What happened?
I am in the process of upgrading from 2.10.3 to 3.0.2.
I have been relying on setting the env var AIRFLOW__CORE__DAG_DISCOVERY_SAFE_MODE=false in order to parse dags from files that don't mention the words DAG & airflow. The configuration shows up as dag_discovery_safe_mode: false in the airflow config page in both versions.
However it does not seem to be taking effect in version 3.0.2. I have confirmed that if I add # DAG airflow to the top of the dag definition file the dag will appear in the airflow ui. This suggests that the dag parser is still in safe mode despite the configuration.
What you think should happen instead?
All files in the /dags folder should be parsed, even if they do not mention DAG and airflow.
How to reproduce
- Set the env var
AIRFLOW__CORE__DAG_DISCOVERY_SAFE_MODE=false - Add file
include/create_dag.py:
from datetime import datetime
from airflow import DAG
from airflow.providers.standard.operators.empty import EmptyOperator
def create_dag():
with DAG(
"test_dag",
default_args={
"owner": "airflow",
"start_date": datetime(2021, 6, 18),
},
):
EmptyOperator(task_id="test")
- Add file
dags/test_dag.py
from include.dag_blueprints.create_dag import create_dag
create_dag()
This will not parse unless # airflow DAG is added to the top
Operating System
Debian
Versions of Apache Airflow Providers
No response
Deployment
Astronomer
Deployment details
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
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
BBQing commentedon Jun 29, 2025
I have tried this example and dag processor reads the file (it is part of the DagBundle), so from this point the dag_discovery_safe_mode works.
But there are no dags discovered in the file.
Once I have added # airflow in the file, the dag was discovered, but it was broken due to ImportError (it did not know the module include).
Did you make any extra steps to make the import folder visible.
BBQing commentedon Jun 29, 2025
Maybe this is problematic:
airflow/airflow-core/src/airflow/dag_processing/processor.py
Line 129 in e455329
BBQing commentedon Jun 29, 2025
This is the output for safe_mode=True
and this the safe_mode=False
Notice the # Errors column
@ashb this might be interesting for you
nicnguyen3103 commentedon Jun 30, 2025
Confirmed that the force safe_mode is the issue. I have checked the logic in the DagBag parse file, everything function normally
BBQing commentedon Jun 30, 2025
I can fix it
NilsJPWerner commentedon Jun 30, 2025
Sorry I had screwed up the paths in the example.
dags/test_dag.pyshould beBBQing commentedon Jul 1, 2025
@NilsJPWerner if run
type(create_dag())in your script, what is the output value? Because if it is not DAG, then it won't be discovered.ashb commentedon Jul 2, 2025
@BBQing That is not true anymore -- as long as somewhere in parsing/executing the top level code
with dagis called, then it will be autoregistered and picked up,i.e. this would be fine and the dag will be picked up:
BBQing commentedon Jul 2, 2025
@ashb @NilsJPWerner My bad, it is in the code after the line checking the instance type - I guess I've got distracted. Anyways it was not relevant for this problem.
dayonet commentedon Apr 29, 2026
Hi,
I have the same issue with
dag_discovery_safe_modenot taking action.We wrote a wapper for Airflow so we don't import from Airflow directly in any of the dag definition files.
When
dag_discovery_safe_mode = truethe DAGs don't show up no matter what.When
dag_discovery_safe_mode = falsethe DAGs appear after runningairflow dags reserialize, but then disappear a few minutes after. Each time reserialization is run the DAGs reappear and then disappear again.Restarting the pods or adding new DAGs do not help. The DAGs keep disappearing unless we add "airflow" and "dag" to the file, which works with
dag_discovery_safe_mode = trueas well.