mirror of
https://github.com/apache/superset.git
synced 2026-04-19 16:14:52 +00:00
feat(mcp): support saved metrics from datasets in chart generation (#38955)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
committed by
GitHub
parent
d331a043a3
commit
15bab227bb
@@ -679,3 +679,53 @@ class TestNormalizeXAxisFilterConsistency:
|
||||
assert normalized.group_by is not None
|
||||
assert normalized.filters is not None
|
||||
assert normalized.group_by[0].name == normalized.filters[0].column == "AIRLINE"
|
||||
|
||||
|
||||
class TestValidateSavedMetrics:
|
||||
"""Test that saved_metric refs are validated against dataset metrics."""
|
||||
|
||||
def test_valid_saved_metric_passes(
|
||||
self, mock_dataset_context: DatasetContext
|
||||
) -> None:
|
||||
config = XYChartConfig(
|
||||
chart_type="xy",
|
||||
x=ColumnRef(name="OrderDate"),
|
||||
y=[ColumnRef(name="TotalRevenue", saved_metric=True)],
|
||||
)
|
||||
is_valid, error = DatasetValidator.validate_against_dataset(
|
||||
config, dataset_id=18, dataset_context=mock_dataset_context
|
||||
)
|
||||
assert is_valid
|
||||
assert error is None
|
||||
|
||||
def test_column_name_as_saved_metric_fails(
|
||||
self, mock_dataset_context: DatasetContext
|
||||
) -> None:
|
||||
"""A regular column marked as saved_metric should be rejected."""
|
||||
config = XYChartConfig(
|
||||
chart_type="xy",
|
||||
x=ColumnRef(name="OrderDate"),
|
||||
y=[ColumnRef(name="Sales", saved_metric=True)],
|
||||
)
|
||||
is_valid, error = DatasetValidator.validate_against_dataset(
|
||||
config, dataset_id=18, dataset_context=mock_dataset_context
|
||||
)
|
||||
assert not is_valid
|
||||
assert error is not None
|
||||
assert error.error_code == "INVALID_SAVED_METRIC"
|
||||
|
||||
def test_nonexistent_saved_metric_fails(
|
||||
self, mock_dataset_context: DatasetContext
|
||||
) -> None:
|
||||
"""A nonexistent saved metric should produce a specific error."""
|
||||
config = XYChartConfig(
|
||||
chart_type="xy",
|
||||
x=ColumnRef(name="OrderDate"),
|
||||
y=[ColumnRef(name="nonexistent_metric", saved_metric=True)],
|
||||
)
|
||||
is_valid, error = DatasetValidator.validate_against_dataset(
|
||||
config, dataset_id=18, dataset_context=mock_dataset_context
|
||||
)
|
||||
assert not is_valid
|
||||
assert error is not None
|
||||
assert error.error_code == "INVALID_SAVED_METRIC"
|
||||
|
||||
Reference in New Issue
Block a user