aminghadersohi commented on code in PR #38402:
URL: https://github.com/apache/superset/pull/38402#discussion_r2911808365
##########
superset/mcp_service/chart/validation/schema_validator.py:
##########
@@ -282,6 +286,70 @@ def _pre_validate_pie_config(
return True, None
+ @staticmethod
+ def _pre_validate_handlebars_config(
+ config: Dict[str, Any],
+ ) -> Tuple[bool, ChartGenerationError | None]:
+ """Pre-validate handlebars chart configuration."""
+ if "handlebars_template" not in config:
+ return False, ChartGenerationError(
+ error_type="missing_handlebars_template",
+ message="Handlebars chart missing required field:
handlebars_template",
+ details="Handlebars charts require a 'handlebars_template'
string "
+ "containing Handlebars HTML template markup",
+ suggestions=[
+ "Add 'handlebars_template' with a Handlebars HTML
template",
+ "Data is available as {{data}} array in the template",
+ "Example: '<ul>{{#each data}}<li>{{this.name}}: "
+ "{{this.value}}</li>{{/each}}</ul>'",
+ ],
+ error_code="MISSING_HANDLEBARS_TEMPLATE",
+ )
+
+ template = config.get("handlebars_template")
+ if not isinstance(template, str) or not template.strip():
+ return False, ChartGenerationError(
+ error_type="invalid_handlebars_template",
+ message="Handlebars template must be a non-empty string",
+ details="The 'handlebars_template' field must be a non-empty
string "
+ "containing valid Handlebars HTML template markup",
+ suggestions=[
+ "Ensure handlebars_template is a non-empty string",
+ "Example: '<ul>{{#each
data}}<li>{{this.name}}</li>{{/each}}</ul>'",
+ ],
+ error_code="INVALID_HANDLEBARS_TEMPLATE",
+ )
+
+ query_mode = config.get("query_mode", "aggregate")
+ if query_mode == "raw" and "columns" not in config:
Review Comment:
This validation is already present at lines 323-334 of `schema_validator.py`
— the code checks `if query_mode not in ('aggregate', 'raw')` and returns an
`INVALID_QUERY_MODE` error with suggestions. Invalid values are caught at
pre-validation, not deferred to Pydantic.
##########
superset/mcp_service/chart/chart_utils.py:
##########
@@ -952,6 +1006,9 @@ def generate_chart_name(
elif isinstance(config, MixedTimeseriesChartConfig):
what = _mixed_timeseries_what(config)
context = _summarize_filters(config.filters)
+ elif isinstance(config, HandlebarsChartConfig):
+ what = _handlebars_chart_what(config)
+ context = _summarize_filters(getattr(config, "filters", None))
else:
return "Chart"
Review Comment:
The function was not removed — `_resolve_viz_type` is defined at line 1021
and called at lines 1051 and 1101 in `chart_utils.py`. It's available for both
`analyze_chart_capabilities` and `analyze_chart_semantics`.
--
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]