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

   <!-- Bito Reply -->
   The flagged issue is correct. The `UpdateDatasetCommand` in Superset 
typically performs a full replacement of the `metrics` and `columns` 
collections. By passing only the new items from the request, existing columns 
or metrics inferred from the SQL query will be overwritten or deleted.
   
   To resolve this, you should fetch the existing dataset's columns and 
metrics, merge them with the new items, and then pass the combined list to the 
`UpdateDatasetCommand`.
   
   Here is the minimal fix for 
`superset/mcp_service/dataset/tool/create_virtual_dataset.py`:
   
   ```python
               if request.metrics or request.calculated_columns:
                   from superset.commands.dataset.update import 
UpdateDatasetCommand
                   
                   update_props: dict[str, Any] = {}
                   if request.metrics:
                       # Merge existing metrics with new ones
                       existing_metrics = [m.to_dict() for m in dataset.metrics]
                       update_props["metrics"] = existing_metrics + 
request.metrics
                   if request.calculated_columns:
                       # Merge existing columns with new ones
                       existing_cols = [c.to_dict() for c in dataset.columns]
                       update_props["columns"] = existing_cols + 
request.calculated_columns
                   
                   with 
event_logger.log_context(action="mcp.create_virtual_dataset.update"):
                       dataset = UpdateDatasetCommand(dataset.id, 
update_props).run()
   ```
   
   Would you like me to check the other comments on this PR and implement fixes 
for them as well?
   
   **superset/mcp_service/dataset/tool/create_virtual_dataset.py**
   ```
   if request.metrics or request.calculated_columns:
                   from superset.commands.dataset.update import 
UpdateDatasetCommand
                   
                   update_props: dict[str, Any] = {}
                   if request.metrics:
                       # Merge existing metrics with new ones
                       existing_metrics = [m.to_dict() for m in dataset.metrics]
                       update_props["metrics"] = existing_metrics + 
request.metrics
                   if request.calculated_columns:
                       # Merge existing columns with new ones
                       existing_cols = [c.to_dict() for c in dataset.columns]
                       update_props["columns"] = existing_cols + 
request.calculated_columns
                   
                   with 
event_logger.log_context(action="mcp.create_virtual_dataset.update"):
                       dataset = UpdateDatasetCommand(dataset.id, 
update_props).run()
   ```


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