bito-code-review[bot] commented on code in PR #40128:
URL: https://github.com/apache/superset/pull/40128#discussion_r3365900662


##########
superset/commands/dashboard/restore.py:
##########
@@ -0,0 +1,93 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""Command to restore a soft-deleted dashboard."""
+
+from superset.commands.dashboard.exceptions import (
+    DashboardForbiddenError,
+    DashboardNotFoundError,
+    DashboardRestoreFailedError,
+    DashboardSlugConflictError,
+)
+from superset.commands.restore import BaseRestoreCommand
+from superset.daos.dashboard import DashboardDAO
+from superset.extensions import db
+from superset.models.dashboard import Dashboard
+
+
+class RestoreDashboardCommand(BaseRestoreCommand[Dashboard]):
+    """Restore a soft-deleted dashboard by clearing its ``deleted_at`` field.
+
+    Most behaviour is inherited from ``BaseRestoreCommand``. The override
+    here adds the slug-conflict check: with the partial unique index on
+    ``slug WHERE deleted_at IS NULL``, slug reuse during the soft-deleted
+    window is allowed, so a restore may now collide with an active row
+    that claimed the slug while this one was deleted. Raise a clean
+    domain error in that case instead of letting the unique-index
+    violation surface as an opaque ``IntegrityError`` at flush time.
+    """
+
+    dao = DashboardDAO
+    not_found_exc = DashboardNotFoundError
+    forbidden_exc = DashboardForbiddenError
+    restore_failed_exc = DashboardRestoreFailedError
+
+    def validate(self) -> Dashboard:  # type: ignore[override]
+        """Extend ``BaseRestoreCommand.validate`` with a slug-conflict 
pre-check.
+
+        Raises ``DashboardSlugConflictError`` when the dashboard has a
+        ``slug`` that has been claimed by another active dashboard while
+        this one was soft-deleted. Surfacing the conflict as a domain
+        error here keeps callers from seeing an opaque ``IntegrityError``
+        at flush time on dialects with the partial index, and a
+        constraint-violation 500 on dialects without it.
+        """
+        model = super().validate()
+        # Check ``is not None`` rather than truthiness: an empty-string slug is
+        # still subject to the partial unique index, so it must be guarded too
+        # (a falsy "" would otherwise skip the pre-check and fail later with an
+        # opaque IntegrityError).
+        if model.slug is not None and self._has_active_slug_twin(model):

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Missing empty-string slug test</b></div>
   <div id="fix">
   
   The fix is correct — `is not None` guards empty-string slugs that the old 
`if model.slug` truthiness check would skip. However, the test suite has no 
case covering `dashboard.slug = ""`; the existing 
`test_restore_dashboard_skips_conflict_check_when_no_slug` only covers `None`. 
Per rule [11730], comprehensive tests should exercise edge cases. Consider 
adding a test with an empty-string slug to confirm the new branch is reachable.
   </div>
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #8da709</i></small>
   </div>
   
   ---
   Should Bito avoid suggestions like this for future reviews? (<a 
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
   - [ ] Yes, avoid them



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