codeant-ai-for-open-source[bot] commented on code in PR #41980:
URL: https://github.com/apache/superset/pull/41980#discussion_r3576050619


##########
superset/utils/core.py:
##########
@@ -641,9 +641,7 @@ def generic_find_constraint_name(
     table: str, columns: set[str], referenced: str, database: SQLAlchemy
 ) -> str | None:
     """Utility to find a constraint name in alembic migrations"""
-    tbl = sa.Table(
-        table, database.metadata, autoload=True, autoload_with=database.engine
-    )
+    tbl = sa.Table(table, database.metadata, autoload_with=database.engine)

Review Comment:
   Yep — this comment is valid.
   
   Using `database.metadata` here is still risky because it may already contain 
ORM-mapped tables, so reflection can reuse stale model metadata instead of 
reading the live DB schema. That makes `generic_find_constraint_name()` 
unreliable in migrations.
   
   A minimal fix is to reflect into a fresh `MetaData()`:
   
   ```python
   def generic_find_constraint_name(
       table: str, columns: set[str], referenced: str, database: SQLAlchemy
   ) -> str | None:
       """Utility to find a constraint name in alembic migrations"""
       metadata = sa.MetaData()
       tbl = sa.Table(table, metadata, autoload_with=database.engine)
   
       for fk in tbl.foreign_key_constraints:
           if fk.referred_table.name == referenced and set(fk.column_keys) == 
columns:
               return fk.name
   
       return None
   ```
   
   That keeps the lookup tied to the migration connection and avoids metadata 
collisions.
   
   If you want, I can also check the other comments on this PR and help with 
the rest of the fixes.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to