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


##########
superset/commands/dashboard/restore.py:
##########
@@ -44,6 +101,81 @@ class 
RestoreDashboardCommand(BaseRestoreCommand[Dashboard]):
     forbidden_exc = DashboardForbiddenError
     restore_failed_exc = DashboardRestoreFailedError
 
+    def prepare_restore(self, model: Dashboard) -> None:
+        """Remove controls with missing semantic targets before making them 
live.
+
+        A missing target invalidates the entire control, including its 
defaults.
+        Do not confuse unavailable providers or lost datasource grants with 
deletion:
+        only metadata existence matters after dashboard editorship was 
validated.
+        """
+        metadata: dict[str, Any] | None = 
_parse_restore_metadata(model.json_metadata)
+        if metadata is None:
+            self.warnings.append(
+                "Warning: dashboard filter cleanup was skipped because its 
metadata "
+                "is malformed. Review the dashboard filters before using its 
results."
+            )
+            return
+        keys: tuple[str, str] = (
+            "native_filter_configuration",
+            "chart_customization_config",
+        )
+        controls: list[dict[str, Any]] = [
+            control for key in keys for control in metadata.get(key) or []
+        ]
+        semantic_ids: dict[int, set[int | None]] = {
+            id(control): {
+                _semantic_target_id(target)
+                for target in control.get("targets") or []
+                if target.get("datasourceType") == "semantic_view"
+            }
+            for control in controls
+        }
+        requested_ids: set[int] = {
+            target_id
+            for ids in semantic_ids.values()
+            for target_id in ids
+            if target_id is not None
+        }
+        existing_ids: set[int] = (
+            set(
+                db.session.scalars(
+                    
select(SemanticView.id).where(SemanticView.id.in_(requested_ids))
+                )

Review Comment:
   **Suggestion:** If metadata contains more distinct semantic IDs than the 
backend's bind-parameter limit, this unbatched `IN` query errors and prevents 
restoring an otherwise valid dashboard.
   
   **Assessment:** ๐ŸŸ  `Major` ยท ๐Ÿ” `Occurrence: Rarely` ยท ๐Ÿท๏ธ `Possible bug`
   
   [![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=2b82d07bfdb84392947f3ecdab003d31&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=2b82d07bfdb84392947f3ecdab003d31&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/commands/dashboard/restore.py
   **Line:** 141:143
   **Comment:**
        *Possible Bug: If metadata contains more distinct semantic IDs than the 
backend's bind-parameter limit, this unbatched `IN` query errors and prevents 
restoring an otherwise valid dashboard.
   
   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%2F45130&comment_hash=9f343efbee36695875b50e2d5d57de0ea8d7b75ef0ab8b55d1973af96dfc4b83&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F45130&comment_hash=9f343efbee36695875b50e2d5d57de0ea8d7b75ef0ab8b55d1973af96dfc4b83&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