aminghadersohi opened a new pull request, #44681:
URL: https://github.com/apache/superset/pull/44681

   ### SUMMARY
   MCP chart responses read `datasource_name` from `Slice.datasource_name`. 
That column is stored and denormalized, and it is not refreshed when a dataset 
is renamed or a chart is re-pointed. So it can disagree with 
`get_dashboard_datasets`, which resolves the dataset through the live 
`Slice.table` join. Also, `ChartInfo` had no `datasource_id` field: 
`list_charts` loaded the column and listed it in `columns_loaded`, then dropped 
it during serialization. That left MCP clients with no way to see a chart's 
real dataset id.
   
   Changes:
   - **Live name.** `resolve_chart_datasource_name` (in 
`mcp_service/chart/schemas.py`) reads the name through 
`Slice.datasource_name_text()`. That method uses the type-guarded `table` / 
`semantic_view` relationships, so semantic-view charts resolve correctly too. 
It is used by `get_chart_info`, `list_charts`, `get_chart_sql` and the chart 
summaries in dashboard responses. If the datasource no longer exists, the name 
is `null` instead of the stale stored string. Row tuples and other objects 
without the resolver fall back to the stored value.
   - **`datasource_id`.** Added to `ChartInfo` and `DashboardChartSummary`. It 
can be requested with `select_columns`, and it is removed or redacted, like the 
other data-model fields, for users without data-model metadata access 
(`remove_chart_data_model_columns` / `redact_chart_data_model_fields`). 
Standalone permalink reads also fill it in from the permalink's datasource.
   - **`list_charts`.**
     - When `datasource_name` is selected, the `table` / `semantic_view` 
relationships are added to the DAO load list. The DAO then returns model 
instances with those relationships eager-loaded, not row tuples, so the live 
name costs no extra per-chart query.
     - `columns_loaded` now lists only fields that appear in the response. It 
drops model columns `ChartInfo` does not expose (e.g. `params`) and 
dependencies loaded only to compute another field.
   
   Tracking: SC-121803.
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   N/A (API response only).
   
   Before: a chart joined to dataset 14 
(`hubspot_customers.hs_flat_customer_events`) whose stored name is 
`superset_events_production.superset_events` reports the stored name and no 
`datasource_id`.
   After: it reports `datasource_id: 14` and `datasource_name: 
"hubspot_customers.hs_flat_customer_events"`.
   
   ### TESTING INSTRUCTIONS
   ```
   pytest tests/unit_tests/mcp_service/chart/test_live_chart_datasource.py
   pytest tests/unit_tests/mcp_service
   ```
   The new tests persist a table-backed chart and a semantic-view chart 
(sharing the same datasource id) whose stored `datasource_name` is stale. They 
also persist a chart whose dataset no longer exists. The charts are reloaded 
from a cold identity map, and the tests check `serialize_chart_object`, 
dashboard chart summaries, `get_chart_sql`'s name resolution, and the 
`get_chart_info` / `list_charts` tools end to end (including redaction without 
data-model access and `columns_loaded`).
   
   ### ADDITIONAL INFORMATION
   - [ ] Has associated issue:
   - [ ] Required feature flags:
   - [ ] Changes UI
   - [ ] Includes DB Migration (follow approval process in 
[SIP-59](https://github.com/apache/superset/issues/13351))
     - [ ] Migration is atomic, supports rollback & is backwards-compatible
     - [ ] Confirm DB migration upgrade and downgrade tested
     - [ ] Runtime estimates and downtime expectations provided
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


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