This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new f1664674d8 - Fixes #42432 (#42770)
f1664674d8 is described below
commit f1664674d859a262e93fb3110557a1e71138ca8b
Author: harjeevan maan <[email protected]>
AuthorDate: Tue Oct 8 20:09:26 2024 -0400
- Fixes #42432 (#42770)
- Added a unit test
---
airflow/utils/db.py | 23 +++++++++++++----------
tests/utils/test_db.py | 9 +++++++++
2 files changed, 22 insertions(+), 10 deletions(-)
diff --git a/airflow/utils/db.py b/airflow/utils/db.py
index c185c70a98..fde641fa9b 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 2a197c2e6c..ce77f80297 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 @@ class TestDb:
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