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

   <!-- Bito Reply -->
   The flagged issue is correct. The current `filter_by(catalog=catalog)` query 
performs an exact match, which fails to retrieve existing datasets where the 
`catalog` column is `NULL` (often representing the default catalog in legacy 
data). This causes the command to incorrectly treat the dataset as new, 
potentially leading to duplicate metadata or failures if the physical table 
already exists.
   
   To resolve this, you should update the query to be null-aware. You can use 
SQLAlchemy's `or_` operator to match either the specific catalog or `NULL` when 
the catalog is the default.
   
   ### Proposed Fix
   
   In `superset/commands/database/uploaders/base.py`, update the query logic:
   
   ```python
   from sqlalchemy import or_
   
   # ...
   
   sqla_table = (
       db.session.query(SqlaTable)
       .filter(
           SqlaTable.table_name == self._table_name,
           SqlaTable.schema == self._schema,
           SqlaTable.database_id == self._model_id,
           or_(SqlaTable.catalog == catalog, SqlaTable.catalog == None),
       )
       .one_or_none()
   )
   ```
   
   I have checked the PR comments, and there are no other pending comments to 
address. Would you like me to proceed with any other changes?
   
   **superset/commands/database/uploaders/base.py**
   ```
   from sqlalchemy import or_
   
   # ...
   
   sqla_table = (
       db.session.query(SqlaTable)
       .filter(
           SqlaTable.table_name == self._table_name,
           SqlaTable.schema == self._schema,
           SqlaTable.database_id == self._model_id,
           or_(SqlaTable.catalog == catalog, SqlaTable.catalog == None),
       )
       .one_or_none()
   )
   ```


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