aminghadersohi commented on code in PR #42490:
URL: https://github.com/apache/superset/pull/42490#discussion_r3769986547
##########
superset/mcp_service/chart/tool/update_chart_preview.py:
##########
@@ -102,6 +103,49 @@ def _get_previous_form_data(form_data_key: str) ->
dict[str, Any] | None:
return None
+def _preserve_previous_adhoc_filters(
+ new_form_data: dict[str, Any], previous_form_data: dict[str, Any]
+) -> None:
+ """Preserve cached filters without dropping mapper-generated bindings."""
+ previous_filters = previous_form_data.get("adhoc_filters")
+ if not isinstance(previous_filters, list) or not previous_filters:
+ return
+
+ generated_filters = new_form_data.get("adhoc_filters", [])
+ previous_binding =
previous_form_data.get(MCP_DASHBOARD_TIME_FILTER_SUBJECT)
+ new_binding = new_form_data.get(MCP_DASHBOARD_TIME_FILTER_SUBJECT)
+ merged_filters = [
+ filter_
+ for filter_ in previous_filters
+ if not (
+ previous_binding
+ and previous_binding != new_binding
Review Comment:
Thanks for checking this edge case. The removal when `new_binding is None`
is intentional and should not receive that guard: the prior filter identified
by `_mcp_dashboard_time_filter_subject` is generated binding state, not an
arbitrary user filter. If the remapped config no longer produces a valid
dashboard binding, retaining it would leave a stale time subject—the exact
failure called out in the earlier CodeAnt/human review.
`_preserve_previous_adhoc_filters` removes only the filter matching the
provenance marker; unrelated cached `TEMPORAL_RANGE` filters are preserved. The
regressions `test_removes_cached_temporal_filter_without_new_binding` and
`test_rebinding_preserves_unrelated_cached_temporal_filter` cover both sides of
this contract.
--
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]