From 8079b4cb69eff3d04a00d897a76e182b575c754c Mon Sep 17 00:00:00 2001 From: Sam Wheating Date: Thu, 31 Mar 2022 14:11:56 -0700 Subject: [PATCH] Remove dag parsing from db init command (#22531) --- airflow/utils/db.py | 18 +++++++++++------- tests/conftest.py | 1 + 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/airflow/utils/db.py b/airflow/utils/db.py index a92d60e9e18c6..fe8591b35c6be 100644 --- a/airflow/utils/db.py +++ b/airflow/utils/db.py @@ -644,13 +644,6 @@ def initdb(session: Session = NEW_SESSION): with create_global_lock(session=session, lock=DBLocks.MIGRATIONS): - dagbag = DagBag() - # Save DAGs in the ORM - dagbag.sync_to_db(session=session) - - # Deactivate the unknown ones - DAG.deactivate_unknown_dags(dagbag.dags.keys(), session=session) - from flask_appbuilder.models.sqla import Base Base.metadata.create_all(settings.engine) @@ -1285,6 +1278,17 @@ def resetdb(session: Session = NEW_SESSION): initdb(session=session) +@provide_session +def bootstrap_dagbag(session: Session = NEW_SESSION): + + dagbag = DagBag() + # Save DAGs in the ORM + dagbag.sync_to_db(session=session) + + # Deactivate the unknown ones + DAG.deactivate_unknown_dags(dagbag.dags.keys(), session=session) + + @provide_session def downgrade(*, to_revision, from_revision=None, show_sql_only=False, session: Session = NEW_SESSION): """ diff --git a/tests/conftest.py b/tests/conftest.py index faf7f83716ca8..ed16ee8004d10 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -169,6 +169,7 @@ def initial_db_init(): from airflow.utils import db db.resetdb() + db.bootstrap_dagbag() @pytest.fixture(autouse=True, scope="session")