Skip to content

Commit

Permalink
Use connection instead of session.get_bind()
Browse files Browse the repository at this point in the history
  • Loading branch information
ephraimbuddy committed May 26, 2023
1 parent 4ea473a commit edbbb7e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions airflow/utils/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -1643,7 +1643,7 @@ def resetdb(session: Session = NEW_SESSION, skip_init: bool = False):
with create_global_lock(session=session, lock=DBLocks.MIGRATIONS):
with connection.begin():
drop_airflow_models(connection)
drop_airflow_moved_tables(session)
drop_airflow_moved_tables(connection)

if not skip_init:
initdb(session=session)
Expand Down Expand Up @@ -1725,11 +1725,11 @@ def drop_airflow_models(connection):
version.drop(connection)


def drop_airflow_moved_tables(session):
def drop_airflow_moved_tables(connection):
from airflow.models.base import Base
from airflow.settings import AIRFLOW_MOVED_TABLE_PREFIX

tables = set(inspect(session.get_bind()).get_table_names())
tables = set(inspect(connection).get_table_names())
to_delete = [Table(x, Base.metadata) for x in tables if x.startswith(AIRFLOW_MOVED_TABLE_PREFIX)]
for tbl in to_delete:
tbl.drop(settings.engine, checkfirst=False)
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def test_resetdb(
session_mock = MagicMock()
resetdb(session_mock, skip_init=skip_init)
mock_drop_airflow.assert_called_once_with(mock_connect.return_value)
mock_drop_moved.assert_called_once_with(session_mock)
mock_drop_moved.assert_called_once_with(mock_connect.return_value)
if skip_init:
mock_init.assert_not_called()
else:
Expand Down

0 comments on commit edbbb7e

Please sign in to comment.