EnxDev commented on code in PR #44113: URL: https://github.com/apache/superset/pull/44113#discussion_r3992359165
########## superset/mcp_service/dashboard/tool/get_dashboard_data.py: ########## @@ -0,0 +1,277 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +""" +Get dashboard data FastMCP tool + +Returns a compact, filter-aware summary of the underlying data across a +dashboard's charts, so an agent can answer analytical questions about the whole +dashboard from a single call instead of fetching each chart separately. +""" + +import logging +from datetime import datetime, timezone +from time import monotonic +from typing import Any, TYPE_CHECKING + +from fastmcp import Context +from superset_core.mcp.decorators import tool, ToolAnnotations + +from superset.extensions import event_logger +from superset.mcp_service.chart.schemas import ( + ChartData, + ChartError, + GetChartDataRequest, +) +from superset.mcp_service.chart.tool.get_chart_data import ( + execute_chart_data, + get_chart_data, +) +from superset.mcp_service.dashboard.schemas import ( + _extract_layout_from_position, + DashboardChartData, + DashboardChartQueryData, + DashboardData, + DashboardError, + GetDashboardDataRequest, +) + +if TYPE_CHECKING: + from superset.models.slice import Slice + +logger = logging.getLogger(__name__) + + +def _completeness( + row_count: int, source_total: int | None, limit: int +) -> tuple[int | None, bool]: + """Resolve (total_rows, truncated) for a query result. Preserves an + authoritative source total when the core supplies one; otherwise the total is + the returned count, or unknown (None) when the fetch hit the cap. Truncated + means fewer rows were returned than exist (capped, or source total > returned). + """ + capped = row_count >= limit + if source_total is not None: Review Comment: **[P1] Treat an equal-at-cap `source_total` as unknown, not authoritative.** In the production path this value comes from `query_result["rowcount"]`, which `QueryContextProcessor` sets to the length of the already limited dataframe; `get_chart_data` also overwrites every query `row_limit` with `fetch_row_limit`. So a dataset with more than 100 rows normally reaches this helper as `(row_count=100, source_total=100, limit=100)`, not with `source_total=None` as the new capped test models. This branch returns `total_rows=100` alongside `truncated=true`, contradicting the schema claim that `total_rows` is the available total and potentially restoring the undercount. Could we preserve a source total when it is greater than the returned count, but return `None` when both values equal the cap? A regression for `_completeness(100, 100, 100)` would cover the actual shape. -- 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]
