codeant-ai-for-open-source[bot] commented on code in PR #44984:
URL: https://github.com/apache/superset/pull/44984#discussion_r4183663572


##########
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:
   **Suggestion:** The metadata schema accepts arbitrary fields inside each 
filter dict, so a truthy scalar `chartsInScope` reaches this loop and raises 
`TypeError` during duplicate-slice copies.
   
   **Assessment:** ๐ŸŸ  `Major` ยท ๐Ÿ” `Occurrence: Rarely` ยท ๐Ÿท๏ธ `Type error`
   
   [![Use CodeAnt 
Skill](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/use-codeant-skill-flat-v2.svg)](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
 [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=2cca2fba27ed4f55a12fb7486a90a329&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=2cca2fba27ed4f55a12fb7486a90a329&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   <details>
   <summary><b>Prompt for AI Agent ๐Ÿค– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset/daos/dashboard.py
   **Line:** 108:113
   **Comment:**
        *Type Error: The metadata schema accepts arbitrary fields inside each 
filter dict, so a truthy scalar `chartsInScope` reaches this loop and raises 
`TypeError` during duplicate-slice copies.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44984&comment_hash=44afd5fa4220775b004d34c80e48fa4680e3f74887bb3b4db0f9d4707ad89798&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44984&comment_hash=44afd5fa4220775b004d34c80e48fa4680e3f74887bb3b4db0f9d4707ad89798&reaction=dislike'>๐Ÿ‘Ž</a>



##########
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
+            ]

Review Comment:
   **Suggestion:** Layer selections encode chart IDs in `scope.selectedLayers`; 
leaving them unchanged makes copied filters target source IDs, so they stop 
applying to duplicated charts after reload.
   
   **Assessment:** ๐ŸŸ  `Major` ยท ๐Ÿ” `Occurrence: Rarely` ยท ๐Ÿท๏ธ `Incomplete 
implementation`
   
   [![Use CodeAnt 
Skill](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/use-codeant-skill-flat-v2.svg)](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
 [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=d26b109455d9458f823f9a7360017829&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=d26b109455d9458f823f9a7360017829&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   <details>
   <summary><b>Prompt for AI Agent ๐Ÿค– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset/daos/dashboard.py
   **Line:** 103:107
   **Comment:**
        *Incomplete Implementation: Layer selections encode chart IDs in 
`scope.selectedLayers`; leaving them unchanged makes copied filters target 
source IDs, so they stop applying to duplicated charts after reload.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44984&comment_hash=08809cfd4ff5eeb472994064e9b2b8c28ac3e0c36eb97046100fb3388e1355ae&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44984&comment_hash=08809cfd4ff5eeb472994064e9b2b8c28ac3e0c36eb97046100fb3388e1355ae&reaction=dislike'>๐Ÿ‘Ž</a>



-- 
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]

Reply via email to