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

   ### SUMMARY
   
   When generating chart previews and data for XY charts with a `group_by` 
dimension via the MCP service, the query context only included `groupby` 
columns but omitted the `x_axis` column. This caused series charts to lose 
their x-axis dimension entirely.
   
   For example, when creating a bar chart with `territory` as x-axis, `year` as 
group_by, and `SUM(sales)` as metric, the resulting query would be:
   ```sql
   SELECT year, SUM(sales) FROM ... GROUP BY year
   ```
   Instead of the correct:
   ```sql
   SELECT territory, year, SUM(sales) FROM ... GROUP BY territory, year
   ```
   
   The bug existed in 4 locations where query contexts are built:
   - `TablePreviewStrategy` in `get_chart_preview.py`
   - `VegaLitePreviewStrategy` in `get_chart_preview.py`
   - Fallback query context in `get_chart_data.py`
   - `generate_preview_from_form_data` in `preview_utils.py`
   
   The fix follows the pattern already used by `ASCIIPreviewStrategy`, which 
correctly included both `x_axis` and `groupby` columns in the query context's 
`columns` list.
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   
   **Before:** Chart preview/data only shows groupby column + metrics (x_axis 
column missing)
   ```
   genre        | SUM(global_sales)
   -------------+------------------
   Platform     | 178.66
   Action       | 76.37
   ...
   ```
   
   **After:** Chart preview/data correctly shows x_axis + groupby + metrics
   ```
   platform | genre        | SUM(global_sales)
   ---------+--------------+------------------
   PS2      | Platform     | 72.51
   GC       | Platform     | 28.66
   ...
   ```
   
   ### TESTING INSTRUCTIONS
   
   1. Start Superset with MCP service enabled
   2. Use an MCP client to generate a bar chart with:
      - x-axis: any categorical column (e.g., `platform`)
      - group_by: another categorical column (e.g., `genre`)
      - metric: any aggregated metric (e.g., `SUM(global_sales)`)
   3. Verify the chart preview (table, vega_lite formats) includes all three 
columns
   4. Verify `get_chart_data` returns data with the x-axis column present
   5. Run tests: `pytest tests/unit_tests/mcp_service/chart/ -v`
   
   ### 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


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