diff --git a/airflow/utils/db.py b/airflow/utils/db.py index c185c70a9811f..fde641fa9b424 100644 --- a/airflow/utils/db.py +++ b/airflow/utils/db.py @@ -1203,19 +1203,22 @@ def resetdb(session: Session = NEW_SESSION, skip_init: bool = False): if not settings.engine: raise RuntimeError("The settings.engine must be set. This is a critical assertion") log.info("Dropping tables that exist") + original_logging_level = logging.root.level + try: + import_all_models() - import_all_models() - - connection = settings.engine.connect() + connection = settings.engine.connect() - with create_global_lock(session=session, lock=DBLocks.MIGRATIONS), connection.begin(): - drop_airflow_models(connection) - drop_airflow_moved_tables(connection) - external_db_manager = RunDBManager() - external_db_manager.drop_tables(session, connection) + with create_global_lock(session=session, lock=DBLocks.MIGRATIONS), connection.begin(): + drop_airflow_models(connection) + drop_airflow_moved_tables(connection) + external_db_manager = RunDBManager() + external_db_manager.drop_tables(session, connection) - if not skip_init: - initdb(session=session) + if not skip_init: + initdb(session=session) + finally: + logging.root.setLevel(original_logging_level) @provide_session diff --git a/tests/utils/test_db.py b/tests/utils/test_db.py index 2a197c2e6cf72..ce77f80297fcf 100644 --- a/tests/utils/test_db.py +++ b/tests/utils/test_db.py @@ -18,6 +18,7 @@ from __future__ import annotations import inspect +import logging import os import re from contextlib import redirect_stdout @@ -229,6 +230,14 @@ def test_resetdb( else: mock_init.assert_called_once_with(session=session_mock) + def test_resetdb_logging_level(self): + unset_logging_level = logging.root.level + logging.root.setLevel(logging.DEBUG) + set_logging_level = logging.root.level + resetdb() + assert logging.root.level == set_logging_level + assert logging.root.level != unset_logging_level + def test_alembic_configuration(self): with mock.patch.dict( os.environ, {"AIRFLOW__DATABASE__ALEMBIC_INI_FILE_PATH": "/tmp/alembic.ini"}, clear=True