codeant-ai-for-open-source[bot] commented on code in PR #40339:
URL: https://github.com/apache/superset/pull/40339#discussion_r3312565478
##########
superset/mcp_service/chart/chart_helpers.py:
##########
@@ -260,6 +260,109 @@ def merge_extra_form_data_filters_into_query(
merge_form_data_filters_into_query(query, extra_query_form_data)
+def _deck_gl_spatial_cols(spatial: dict[str, Any] | None) -> list[str]:
+ """Return the column names referenced by a single Deck.gl spatial
control."""
+ if not isinstance(spatial, dict):
+ return []
+ spatial_type = spatial.get("type")
+ if spatial_type == "latlong":
+ return [c for c in [spatial.get("lonCol"), spatial.get("latCol")] if c]
+ if spatial_type == "delimited":
+ return [c for c in [spatial.get("lonlatCol")] if c]
+ if spatial_type == "geohash":
+ return [c for c in [spatial.get("geohashCol")] if c]
+ return []
+
+
+def _deck_gl_tooltip_cols(tooltip_contents: list[Any] | None) -> list[str]:
+ """Return column names from Deck.gl tooltip_contents config."""
+ cols: list[str] = []
+ for item in tooltip_contents or []:
+ if isinstance(item, str):
+ cols.append(item)
+ elif isinstance(item, dict) and item.get("item_type") == "column":
+ col = item.get("column_name")
+ if isinstance(col, str) and col:
+ cols.append(col)
+ return cols
+
+
+def _deck_gl_null_filters(form_data: dict[str, Any]) -> list[dict[str, Any]]:
+ """Build IS NOT NULL simple filters for Deck.gl spatial and line columns.
+
+ Mirrors BaseDeckGLViz.add_null_filters() behavior: spatial control columns
+ and line_column are filtered for non-null values by default.
+ """
+ seen: set[str] = set()
+ result: list[dict[str, Any]] = []
+ for key in ("spatial", "start_spatial", "end_spatial"):
+ for col in _deck_gl_spatial_cols(form_data.get(key)):
+ if col not in seen:
+ seen.add(col)
+ result.append({"col": col, "op": "IS NOT NULL", "val": ""})
+ line_col = form_data.get("line_column")
+ if isinstance(line_col, str) and line_col and line_col not in seen:
+ result.append({"col": line_col, "op": "IS NOT NULL", "val": ""})
+ return result
+
+
+def _resolve_deck_gl_metrics(form_data: dict[str, Any]) -> list[Any]:
+ """Extract metrics for Deck.gl chart types.
+
+ deck_scatter and deck_polygon can store metric-backed values in
+ point_radius_fixed (radius for scatter, elevation for polygon).
+ deck_polygon may have both a base metric and an elevation metric.
+ """
+ metrics: list[Any] = []
+ for field in ("size", "metric"):
+ m = form_data.get(field)
+ if m:
+ metrics.append(m)
Review Comment:
**Suggestion:** `_resolve_deck_gl_metrics` treats any truthy `size` value as
a metric, but many Deck.gl forms carry non-metric size values (for example
fixed numeric strings like `"100"` in legacy/geojson/path form data). This
causes fallback queries to include invalid metric names and fail at runtime
during metric resolution. Restrict `size` extraction to chart types where
`size` is truly a metric input and validate that the value is a metric
reference/definition before appending it. [api mismatch]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ❌ MCP get_chart_data fails for affected Deck.gl charts.
- ❌ Deck.gl charts with fixed-size settings break fallback queries.
- ⚠️ LLM clients cannot retrieve data for these legacy charts.
- ⚠️ Operators see engine/metric resolution errors instead of chart data.
```
</details>
<details>
<summary><b>Steps of Reproduction ✅ </b></summary>
```mdx
1. Create or locate a Deck.gl chart (for example, a `deck_hex` or
`deck_geojson` chart)
whose saved form_data (stored in `Slice.params`) includes a non-metric
`size` value, such
as a fixed numeric string `"100"` instead of a metric definition; Deck.gl
backend classes
read `form_data["size"]` as the metric for aggregated layers via
`BaseDeckGLViz.get_metrics()` (see `superset/viz.py:40-45` and surrounding
code where
`self.metric = self.form_data.get("size")`).
2. Ensure this chart has no saved `query_context` (typical for older charts
that predate
query_context), so that in the MCP tool path `chart.query_context` is falsy
and the
fallback logic in `get_chart_data` is used (see
`superset/mcp_service/chart/tool/get_chart_data.py:57-64` where a missing
`query_context_json` triggers the form_data fallback branch).
3. Call the MCP tool `get_chart_data` with this chart's identifier
(entrypoint
`get_chart_data()` at
`superset/mcp_service/chart/tool/get_chart_data.py:108-113`),
without a `form_data_key`, so the code loads `form_data` from `chart.params`
and builds
fallback queries via `build_query_dicts_from_form_data` (see lines `88-96`
where
`fallback_queries = build_query_dicts_from_form_data(form_data,
chart.datasource_id,
chart.datasource_type, ...)`).
4. In `build_query_dicts_from_form_data`
(`superset/mcp_service/chart/chart_helpers.py:105-147`), since `viz_type`
starts with
`"deck_"`, the Deck.gl branch is taken: `deck_metrics =
_resolve_deck_gl_metrics(form_data)` (line `135`). Inside
`_resolve_deck_gl_metrics`
(lines `80-97`), the non-metric but truthy `size` value is appended to
`metrics` by the
loop `for field in ("size", "metric"):` / `if m: metrics.append(m)` (lines
`317-320` from
the diff). The resulting `fallback_queries` contain `"metrics": ["100"]`.
When
`QueryContextFactory` and `ChartDataCommand` execute this query in
`get_chart_data` (lines
`123-171`), the engine tries to interpret `"100"` as a metric/column,
leading to a runtime
error (for example, an invalid column or metric resolution error) instead of
returning
data for the chart.
```
</details>
[Fix in
Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=24c7742c099a4393b89c78d33138231d&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
| [Fix in VSCode
Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=24c7742c099a4393b89c78d33138231d&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
*(Use Cmd/Ctrl + Click for best experience)*
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset/mcp_service/chart/chart_helpers.py
**Line:** 317:320
**Comment:**
*Api Mismatch: `_resolve_deck_gl_metrics` treats any truthy `size`
value as a metric, but many Deck.gl forms carry non-metric size values (for
example fixed numeric strings like `"100"` in legacy/geojson/path form data).
This causes fallback queries to include invalid metric names and fail at
runtime during metric resolution. Restrict `size` extraction to chart types
where `size` is truly a metric input and validate that the value is a metric
reference/definition before appending it.
Validate the correctness of the flagged issue. If correct, How can I resolve
this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask
user if the user wants to fix the rest of the comments as well. if said yes,
then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40339&comment_hash=23da707281ce5083d3fbfa69cb6d3710fc1172b0a68209a29c843a2d4e835ad2&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40339&comment_hash=23da707281ce5083d3fbfa69cb6d3710fc1172b0a68209a29c843a2d4e835ad2&reaction=dislike'>👎</a>
--
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]