bito-code-review[bot] commented on code in PR #44984:
URL: https://github.com/apache/superset/pull/44984#discussion_r4183680503
##########
superset/daos/dashboard.py:
##########
@@ -87,6 +87,32 @@
}
+def _remap_native_filter_chart_ids(
+ metadata: dict[str, Any], id_map: dict[int, int]
+) -> None:
+ """Point native filter ``scope.excluded`` and ``chartsInScope`` at new
charts.
+
+ Used when a dashboard is copied along with its charts. Left alone, these
+ ids keep referring to the original dashboard's charts, so the filters stop
+ applying to the duplicated ones once the copy is reloaded. Ids missing from
+ ``id_map`` belong to no chart on the copy and are dropped.
+ """
+ for native_filter in metadata.get("native_filter_configuration") or []:
+ if not isinstance(native_filter, dict):
+ continue
+ scope = native_filter.get("scope")
+ if isinstance(scope, dict) and scope.get("excluded"):
+ scope["excluded"] = [
+ id_map[chart_id] for chart_id in scope["excluded"] if chart_id
in id_map
+ ]
+ if native_filter.get("chartsInScope"):
+ native_filter["chartsInScope"] = [
+ id_map[chart_id]
+ for chart_id in native_filter["chartsInScope"]
+ if chart_id in id_map
+ ]
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Cross-filter ids not remapped</b></div>
<div id="fix">
`_remap_native_filter_chart_ids` only rewrites
`native_filter_configuration`, but cross-filter config
(`global_chart_configuration` and per-chart
`chart_configuration[*]["crossFilters"]`) also denormalizes chart ids into
`scope.excluded`/`chartsInScope`. `export.py` `remap_scope` handles all three;
here the copy leaves cross-filters pointing at the original dashboard's chart
ids, so cross-filtering is wrong on the duplicated dashboard. `scope.excluded`
is authoritative at runtime (`filter_scope.get_chart_ids_in_scope`).
</div>
</div>
<small><i>Code Review Run #1465c5</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]