bito-code-review[bot] commented on code in PR #42490:
URL: https://github.com/apache/superset/pull/42490#discussion_r3786534109
##########
superset/mcp_service/chart/chart_utils.py:
##########
@@ -802,6 +754,86 @@ def _ensure_temporal_adhoc_filter(form_data: Dict[str,
Any], column: str) -> Non
form_data["adhoc_filters"] = existing
+def _bind_dashboard_time_range_filter(
+ form_data: Dict[str, Any],
+ config: ChartConfig,
+ dataset_id: int | str | None,
+) -> None:
+ """Bind charts without time configuration to a temporal filter subject."""
+ if temporal_column := getattr(config, "temporal_column", None):
+ if _is_temporal_for_dashboard_binding(temporal_column, dataset_id):
+ granularity = form_data.get("granularity_sqla")
+ if isinstance(granularity, str) and granularity != temporal_column:
+ # QueryContextFactory gives granularity precedence over a
temporal
+ # filter, so a different granularity would bind both columns.
+ form_data["granularity_sqla"] = None
+ _ensure_temporal_adhoc_filter(form_data, temporal_column)
+ form_data[MCP_DASHBOARD_TIME_FILTER_SUBJECT] = temporal_column
+ return
+
+ dataset = None
+ if dataset_id:
+ try:
+ dataset = _find_dataset_by_id_or_uuid(dataset_id)
+ except (AttributeError, RuntimeError, ValueError, SQLAlchemyError) as
ex:
+ logger.debug(
+ "Could not resolve dataset %s for dashboard time binding: %s",
+ dataset_id,
+ ex,
+ )
+ return
+
+ granularity = form_data.get("granularity_sqla")
+ if isinstance(granularity, str) and _is_temporal_for_dashboard_binding(
+ granularity, dataset_id, dataset
+ ):
+ # Temporal XY mappers create the neutral filter before this binding
pass.
+ # Record its provenance so preview updates can replace it if the
subject
+ # changes, without treating user-authored temporal ranges as generated.
+ if any(
+ isinstance(filter_, dict)
+ and filter_.get("operator") == FilterOperator.TEMPORAL_RANGE.value
+ and filter_.get("subject") == granularity
+ and filter_.get("comparator") == NO_TIME_RANGE
+ for filter_ in form_data.get("adhoc_filters", [])
+ ):
+ form_data[MCP_DASHBOARD_TIME_FILTER_SUBJECT] = granularity
+ return
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Missing test for granularity_sqla branch</b></div>
<div id="fix">
No test exercises the `granularity_sqla` temporal binding path in
`_bind_dashboard_time_range_filter` (lines 790-800). Rule 11731 requires
dedicated unit tests for all new MCP mutation tool logic. Without coverage,
this path silently breaks on future refactors.
</div>
</div>
<small><i>Code Review Run #20edcc</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
--
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]