You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by vi...@apache.org on 2026/04/06 16:04:29 UTC
(superset) branch master updated: fix(migrations): check pre-existing foreign keys on create util (#39099)
This is an automated email from the ASF dual-hosted git repository.
villebro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/master by this push:
new 7c79b9ab618 fix(migrations): check pre-existing foreign keys on create util (#39099)
7c79b9ab618 is described below
commit 7c79b9ab6184cf42571f316e81e52767e044fa8d
Author: Ville Brofeldt <33...@users.noreply.github.com>
AuthorDate: Mon Apr 6 09:04:22 2026 -0700
fix(migrations): check pre-existing foreign keys on create util (#39099)
---
superset/migrations/shared/utils.py | 27 +++++++++++++++++++++++++--
1 file changed, 25 insertions(+), 2 deletions(-)
diff --git a/superset/migrations/shared/utils.py b/superset/migrations/shared/utils.py
index dbcfa2f9f5b..f91f3d1a45e 100644
--- a/superset/migrations/shared/utils.py
+++ b/superset/migrations/shared/utils.py
@@ -199,6 +199,18 @@ def has_table(table_name: str) -> bool:
return table_exists
+def get_foreign_key_names(table_name: str) -> set[str]:
+ """
+ Get the set of foreign key constraint names for a table.
+
+ :param table_name: The table name
+ :returns: A set of foreign key constraint names
+ """
+ connection = op.get_bind()
+ inspector = Inspector.from_engine(connection)
+ return {fk["name"] for fk in inspector.get_foreign_keys(table_name)}
+
+
def drop_fks_for_table(
table_name: str, foreign_key_names: list[str] | None = None
) -> None:
@@ -211,13 +223,12 @@ def drop_fks_for_table(
If None is provided, all will be dropped.
"""
connection = op.get_bind()
- inspector = Inspector.from_engine(connection)
if isinstance(connection.dialect, SQLiteDialect):
return # sqlite doesn't like constraints
if has_table(table_name):
- existing_fks = {fk["name"] for fk in inspector.get_foreign_keys(table_name)}
+ existing_fks = get_foreign_key_names(table_name)
# What to delete based on whether the list was passed
if foreign_key_names is not None:
@@ -523,6 +534,18 @@ def create_fks_for_table(
)
return
+ if foreign_key_name in get_foreign_key_names(table_name):
+ logger.info(
+ "Foreign key %s%s%s already exists on table %s%s%s. Skipping...",
+ GREEN,
+ foreign_key_name,
+ RESET,
+ GREEN,
+ table_name,
+ RESET,
+ )
+ return
+
if isinstance(connection.dialect, SQLiteDialect):
# SQLite requires batch mode since ALTER TABLE is limited
with op.batch_alter_table(table_name) as batch_op: