This is an automated email from the ASF dual-hosted git repository.
ephraimanierobi 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 40eefd8479 Fix `airflow db reset` when dangling tables exist (#25441)
40eefd8479 is described below
commit 40eefd84797f5085e6c3fef6cbd6f713ceb3c3d8
Author: Ash Berlin-Taylor <[email protected]>
AuthorDate: Mon Aug 1 13:58:31 2022 +0100
Fix `airflow db reset` when dangling tables exist (#25441)
If one of the "dangling" tables already existed in the DB, performing an
`airflow db reset` would delete the tables, but it would then try and
_re-create_ the table later. This was because the Table object was still
associated with the Metadata object.
The fix is to remove the it from Metadata once we have dropped it.
---
airflow/utils/db.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/airflow/utils/db.py b/airflow/utils/db.py
index da10e9bd4b..b52b7dfd8b 100644
--- a/airflow/utils/db.py
+++ b/airflow/utils/db.py
@@ -1640,7 +1640,8 @@ def drop_airflow_moved_tables(session):
tables = set(inspect(session.get_bind()).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=True)
+ tbl.drop(settings.engine, checkfirst=False)
+ Base.metadata.remove(tbl)
def drop_flask_models(connection):