aminghadersohi commented on PR #36937:
URL: https://github.com/apache/superset/pull/36937#issuecomment-3719130145
## Addressed Vitor's Feedback
Thanks @vitor.avila for the detailed feedback! You were absolutely right.
### The Problem
The original implementation was manually constructing a query from
`form_data` parts (`groupby`, `metrics`, `filters`), which doesn't produce the
same results as the chart visualization. For a line chart with annual
aggregation, this was returning aggregated totals instead of the actual data
points.
### The Fix
Now `get_chart_data` uses **`chart.query_context`** (the saved query
context) exactly like the `/api/v1/chart/{id}/data` endpoint does:
```python
# Before (wrong approach):
query_spec = {
"columns": form_data.get("groupby", []),
"metrics": form_data.get("metrics", []),
...
}
# After (correct approach - same as API):
query_context_json = json.loads(chart.query_context)
query_context = ChartDataQueryContextSchema().load(query_context_json)
```
The `query_context` contains all the information needed to reproduce the
chart's data exactly as shown in the visualization.
### Changes in this commit:
1. Uses `chart.query_context` for data retrieval (same as
`/api/v1/chart/{id}/data`)
2. Falls back to `form_data` construction only if `query_context` is
unavailable
3. Removed `include_raw_data` option (was solving the wrong problem)
4. Row limit override still works and is capped at 10000 for safety
### Testing
Unfortunately I don't have MCP running locally with a Preset instance to
test against. Could you verify this fix works correctly with your line chart
example?
--
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]