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


##########
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:
   ✅ **Customized review instruction saved!**
   
   **Instruction:**
   > Do not flag bind-parameter-limit risks for unbatched IN queries over 
semantic-view IDs collected from a single dashboard’s native filters and 
display controls; their realistic cardinality is only dozens, well below 
backend limits.
   
   **Applied to:**
     - `superset/commands/dashboard/restore.py`
   
   ---
   💡 *To manage or update this instruction, visit: [CodeAnt AI 
Settings](https://app.codeant.ai/org/settings/learnings)*



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