mikebridge commented on code in PR #45130:
URL: https://github.com/apache/superset/pull/45130#discussion_r4235493948


##########
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:
   Not worth handling. These IDs come from the semantic-view targets in one 
dashboard's native filters and display controls, which is realistically dozens, 
nowhere near the SQLite (32766) or Postgres (65535) bind limits. The v1 
dashboard importer already runs the same unbatched 
`Slice.id.in_(target_chart_ids)` over that dashboard data 
(`superset/commands/dashboard/importers/v1/__init__.py:308`).



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