bito-code-review[bot] commented on code in PR #38403:
URL: https://github.com/apache/superset/pull/38403#discussion_r3016309080
##########
superset/mcp_service/chart/validation/schema_validator.py:
##########
@@ -282,6 +286,60 @@ def _pre_validate_pie_config(
return True, None
+ @staticmethod
+ def _pre_validate_big_number_config(
+ config: Dict[str, Any],
+ ) -> Tuple[bool, ChartGenerationError | None]:
+ """Pre-validate big number chart configuration."""
+ if "metric" not in config:
+ return False, ChartGenerationError(
+ error_type="missing_metric",
+ message="Big Number chart missing required field: metric",
+ details="Big Number charts require a 'metric' field "
+ "specifying the value to display",
+ suggestions=[
+ "Add 'metric' with name and aggregate: "
+ "{'name': 'revenue', 'aggregate': 'SUM'}",
+ "The aggregate function is required (SUM, COUNT, AVG, MIN,
MAX)",
+ "Example: {'chart_type': 'big_number', "
+ "'metric': {'name': 'sales', 'aggregate': 'SUM'}}",
+ ],
+ error_code="MISSING_BIG_NUMBER_METRIC",
+ )
+
+ metric = config.get("metric", {})
+ if isinstance(metric, dict) and not metric.get("aggregate"):
+ return False, ChartGenerationError(
+ error_type="missing_metric_aggregate",
+ message="Big Number metric must include an aggregate function",
+ details="The metric 'aggregate' field is required "
+ "for Big Number charts",
+ suggestions=[
+ "Add 'aggregate' to your metric: "
+ "{'name': 'col', 'aggregate': 'SUM'}",
+ "Valid aggregates: SUM, COUNT, AVG, MIN, MAX",
+ ],
+ error_code="MISSING_BIG_NUMBER_AGGREGATE",
+ )
Review Comment:
<!-- Bito Reply -->
Yes, the change adds an `isinstance(metric, dict)` check to validate the
metric type, providing a clear error for non-dict inputs. It also enforces the
aggregate field presence and validity.
**superset/mcp_service/chart/validation/schema_validator.py**
```
+ if not isinstance(metric, dict):
+ return False, ChartGenerationError(
+ error_type="invalid_metric_type",
+ message="Big Number metric must be a dictionary",
+ details="The 'metric' field must be an object with 'name'
and 'aggregate'",
+ suggestions=[
+ "Provide metric as: {'name': 'column', 'aggregate':
'SUM'}",
+ ],
+ error_code="INVALID_METRIC_TYPE",
+ )
```
--
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]