codeant-ai-for-open-source[bot] commented on code in PR #42070:
URL: https://github.com/apache/superset/pull/42070#discussion_r3599844909
##########
superset/mcp_service/chart/chart_utils.py:
##########
@@ -951,6 +952,41 @@ def map_box_plot_config(config: "BoxPlotChartConfig") ->
Dict[str, Any]:
return form_data
+def map_waterfall_config(config: WaterfallChartConfig) -> Dict[str, Any]:
+ """Map waterfall config to Superset form_data (viz_type waterfall).
+
+ Matches the frontend Waterfall buildQuery contract: a single ``x_axis``
+ column, an optional single-select ``groupby`` breakdown, and one
+ ``metric``; the query orders by the axis columns ascending, which the
+ frontend derives from these keys.
+ """
+ form_data: Dict[str, Any] = {
+ "viz_type": "waterfall",
+ "x_axis": config.x_axis.name,
+ "groupby": [config.breakdown.name] if config.breakdown else [],
+ "metric": create_metric_object(config.metric),
+ "show_total": config.show_total,
+ "show_legend": config.show_legend,
+ "increase_label": config.increase_label,
+ "decrease_label": config.decrease_label,
+ "total_label": config.total_label,
+ "x_axis_time_format": config.x_axis_time_format,
+ "y_axis_format": config.y_axis_format,
+ "row_limit": config.row_limit,
+ }
+ # Bucket a temporal x_axis: the grain (time_grain_sqla) needs the temporal
+ # column it applies to (granularity_sqla), mirroring the xy path's
+ # configure_temporal_handling and the frontend buildQuery's
+ # `x_axis || granularity_sqla`. Providing time_grain signals temporal
+ # intent; Superset ignores both for a non-temporal column.
+ if config.time_grain:
+ form_data["time_grain_sqla"] = config.time_grain
+ form_data["granularity_sqla"] = config.x_axis.name
Review Comment:
**Suggestion:** The mapper applies `time_grain_sqla`/`granularity_sqla`
whenever `time_grain` is provided, without checking whether `x_axis` is
actually temporal. For non-temporal columns this can trigger invalid date-trunc
SQL at query time instead of being ignored as documented. Gate this assignment
behind a real temporal-type check (like the XY path) and only set these keys
when the axis column is temporal. [logic error]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ❌ generate_chart waterfall fails for non-temporal x_axis with time_grain.
- ⚠️ Behavior contradicts schema docs claiming grain ignored non-temporal.
- ⚠️ LLM clients see SQL errors instead of graceful fallback.
```
</details>
<details>
<summary><b>Steps of Reproduction ✅ </b></summary>
```mdx
1. Call the MCP `generate_chart` tool defined in
`superset/mcp_service/chart/tool/generate_chart.py:98-111` with a
`GenerateChartRequest`
whose `config` is a `WaterfallChartConfig` (schema at
`superset/mcp_service/chart/schemas.py:5-34`) using `chart_type="waterfall"`,
`x_axis={"name": "year"}` where `year` is a non-temporal numeric column
(e.g. BIGINT as
described in `is_column_truly_temporal` at
`superset/mcp_service/chart/chart_utils.py:300-302`), and `time_grain="P1Y"`.
2. The request passes schema validation because
`WaterfallChartConfig.time_grain` (lines
`28-33` in `schemas.py`) only documents that the grain is "ignored for a
non-temporal
x_axis" but does not enforce any type constraint on `x_axis`, and dataset
validation (via
`DatasetValidator` used in `WaterfallChartPlugin.normalize_column_refs` at
`superset/mcp_service/chart/plugins/waterfall.py:105-126`) only checks
column existence,
not temporal type.
3. During chart generation, `map_config_to_form_data` at
`superset/mcp_service/chart/chart_utils.py:369-416` looks up the
`WaterfallChartPlugin`,
whose `to_form_data` method (`plugins/waterfall.py:88-91`) calls
`map_waterfall_config(config)`; inside `map_waterfall_config`
(`chart_utils.py:955-987`),
lines `982-984` unconditionally set `form_data["time_grain_sqla"] =
config.time_grain` and
`form_data["granularity_sqla"] = config.x_axis.name` whenever
`config.time_grain` is
provided, without any temporal-type check like `configure_temporal_handling`
uses for XY
charts at `chart_utils.py:683-707`.
4. The validation/compile tier then calls `_compile_chart` in
`superset/mcp_service/chart/compile.py:100-152`, which builds a
`QueryContext` using
`QueryContextFactory.create` with the `form_data` containing
`granularity_sqla="year"` and
`time_grain_sqla="P1Y"`; downstream, the SQL construction path for the
datasource (via
`QueryObject` in `superset/common/query_object.py` and the SQLA connector)
applies the
time grain to `granularity` as a datetime field, leading to the exact
failure scenario
documented in `is_column_truly_temporal` (`chart_utils.py:300-302`:
DATE_TRUNC on
BIGINT/INTEGER fails), causing a `ChartDataCommand` error and a
`CompileResult` with
`success=False` and `error_code="CHART_COMPILE_FAILED"` instead of silently
ignoring the
grain for the non-temporal `x_axis`.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=09ca81d291d046ad87977babcde74f61&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
[](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=09ca81d291d046ad87977babcde74f61&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_utils.py
**Line:** 982:984
**Comment:**
*Logic Error: The mapper applies `time_grain_sqla`/`granularity_sqla`
whenever `time_grain` is provided, without checking whether `x_axis` is
actually temporal. For non-temporal columns this can trigger invalid date-trunc
SQL at query time instead of being ignored as documented. Gate this assignment
behind a real temporal-type check (like the XY path) and only set these keys
when the axis column is temporal.
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%2F42070&comment_hash=f158eaa317ecd13169bc0c5d15f1597e49554a5942674fc746ecc6448ec8b5a5&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42070&comment_hash=f158eaa317ecd13169bc0c5d15f1597e49554a5942674fc746ecc6448ec8b5a5&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]