bito-code-review[bot] commented on PR #42897:
URL: https://github.com/apache/superset/pull/42897#issuecomment-5220696071

   <!-- Bito Reply -->
   The review comment correctly identifies a MySQL limitation where a table 
cannot be modified (deleted from) while being read in a subquery. To resolve 
this in a database-agnostic way, you should fetch the IDs to keep into a Python 
list first, then perform the deletion using that list.
   
   Here is the corrected `upgrade` function for 
`superset/migrations/versions/2026-08-07_09-00_da0e3f0081bf_enforce_oauth2_token_uniqueness.py`:
   
   ```python
   def upgrade() -> None:
       bind = op.get_bind()
       metadata = sa.MetaData()
       table = sa.Table(TABLE_NAME, metadata, autoload_with=bind)
   
       # Fetch IDs to keep into memory to avoid MySQL 1093 error
       keep_ids = bind.execute(
           select(func.max(table.c.id))
           .group_by(table.c.user_id, table.c.database_id)
       ).scalars().all()
   
       bind.execute(table.delete().where(table.c.id.notin_(keep_ids)))
   
       drop_index(TABLE_NAME, INDEX_NAME)
       create_index(TABLE_NAME, INDEX_NAME, ["user_id", "database_id"], 
unique=True)
   ```
   
   
**superset/migrations/versions/2026-08-07_09-00_da0e3f0081bf_enforce_oauth2_token_uniqueness.py**
   ```
   # Fetch IDs to keep into memory to avoid MySQL 1093 error
       keep_ids = bind.execute(
           select(func.max(table.c.id))
           .group_by(table.c.user_id, table.c.database_id)
       ).scalars().all()
   
       bind.execute(table.delete().where(table.c.id.notin_(keep_ids)))
   ```


-- 
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