rusackas commented on code in PR #44307:
URL: https://github.com/apache/superset/pull/44307#discussion_r4320630329


##########
superset/commands/dashboard/importers/v1/__init__.py:
##########
@@ -88,6 +88,51 @@ def __init__(self, contents: dict[str, str], *args: Any, 
**kwargs: Any) -> None:
         self.overwrite_all = kwargs.pop("overwrite_all", False)
         super().__init__(contents, *args, **kwargs)
 
+    def _prevent_overwrite_existing_model(  # pylint: disable=invalid-name
+        self, exceptions: list[ValidationError]
+    ) -> None:
+        """Dashboards are also identified by ``slug`` on import.
+
+        ``import_dashboard()`` resolves a config carrying a fresh UUID but a
+        slug owned by an existing *active* dashboard onto that row, so the
+        overwrite gate must treat that collision like a UUID match: without
+        ``overwrite`` the import would silently merge the bundle's charts
+        into the slug-owning dashboard, and with ``overwrite`` it would
+        replace a dashboard the user never saw in the confirmation prompt
+        (which lists files, not UUIDs). The message matches the UUID branch
+        verbatim so the ImportModal's ``already exists`` detection keeps
+        working; soft-deleted owners are left to the restore path.
+        """
+        super()._prevent_overwrite_existing_model(exceptions)
+        if self.overwrite:
+            return
+        for file_name, config in self._configs.items():
+            slug = config.get("slug")
+            # ``slug is None`` rather than ``not slug``: ``import_dashboard()``
+            # resolves a slug collision with ``is not None``, so an 
empty-string
+            # slug is an identity value there and must be gated here too.
+            if slug is None or not file_name.startswith(self.prefix):
+                continue

Review Comment:
   "Good catch, @EnxDev! Pushed a fix using `find_existing_for_import` like you 
suggested, with a regression test for the soft-deleted-UUID-with-claimed-slug 
case."



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