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


##########
tests/unit_tests/commands/dashboard/restore_test.py:
##########
@@ -0,0 +1,201 @@
+# 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.
+"""Unit tests for RestoreDashboardCommand."""
+
+from __future__ import annotations
+
+from datetime import datetime, timezone
+from unittest.mock import MagicMock, patch
+
+import pytest
+
+
+def test_restore_dashboard_not_found_raises(app_context: None) -> None:
+    """RestoreDashboardCommand raises DashboardNotFoundError for missing 
dashboard."""
+    from superset.commands.dashboard.exceptions import DashboardNotFoundError
+    from superset.commands.dashboard.restore import RestoreDashboardCommand
+
+    with patch("superset.daos.dashboard.DashboardDAO.find_by_id", 
return_value=None):
+        cmd = RestoreDashboardCommand("999")
+        with pytest.raises(DashboardNotFoundError):
+            cmd.run()
+
+
+def test_restore_active_dashboard_raises_not_found(app_context: None) -> None:
+    """RestoreDashboardCommand raises DashboardNotFoundError for non-deleted 
dashboard."""  # noqa: E501
+    from superset.commands.dashboard.exceptions import DashboardNotFoundError
+    from superset.commands.dashboard.restore import RestoreDashboardCommand
+
+    dashboard = MagicMock()
+    dashboard.deleted_at = None  # not soft-deleted
+
+    with patch(
+        "superset.daos.dashboard.DashboardDAO.find_by_id", 
return_value=dashboard
+    ):
+        cmd = RestoreDashboardCommand("1")
+        with pytest.raises(DashboardNotFoundError):
+            cmd.run()
+
+
+def test_restore_dashboard_forbidden_raises(app_context: None) -> None:
+    """RestoreDashboardCommand raises DashboardForbiddenError on permission 
check."""
+    from superset.commands.dashboard.exceptions import DashboardForbiddenError
+    from superset.commands.dashboard.restore import RestoreDashboardCommand
+    from superset.exceptions import SupersetSecurityException
+
+    dashboard = MagicMock()
+    dashboard.deleted_at = datetime(2026, 1, 1, tzinfo=timezone.utc)
+
+    def raise_security(*args: object, **kwargs: object) -> None:
+        raise SupersetSecurityException(MagicMock())
+
+    with (
+        patch(
+            "superset.daos.dashboard.DashboardDAO.find_by_id", 
return_value=dashboard
+        ),
+        patch("superset.commands.restore.security_manager") as mock_sec,
+    ):
+        mock_sec.raise_for_ownership = raise_security
+
+        cmd = RestoreDashboardCommand("1")
+        with pytest.raises(DashboardForbiddenError):
+            cmd.run()
+
+
+def test_restore_dashboard_slug_conflict_raises(app_context: None) -> None:
+    """Restore raises DashboardSlugConflictError when slug is now claimed by 
an active dashboard.
+
+    The partial unique index ``WHERE deleted_at IS NULL`` allows another
+    dashboard to claim the slug while this one was soft-deleted. The
+    command catches that case before flushing so the operator sees a
+    domain-specific error instead of an opaque unique-index violation.
+    """  # noqa: E501
+    from superset.commands.dashboard.exceptions import 
DashboardSlugConflictError
+    from superset.commands.dashboard.restore import RestoreDashboardCommand
+
+    dashboard = MagicMock()
+    dashboard.deleted_at = datetime(2026, 1, 1, tzinfo=timezone.utc)
+    dashboard.slug = "q1-report"
+    dashboard.id = 42
+
+    with (
+        patch(
+            "superset.daos.dashboard.DashboardDAO.find_by_id", 
return_value=dashboard
+        ),
+        patch("superset.commands.restore.security_manager") as mock_sec,
+        patch.object(
+            RestoreDashboardCommand, "_has_active_slug_twin", return_value=True
+        ) as mock_twin_check,
+    ):
+        mock_sec.raise_for_ownership.return_value = None
+
+        cmd = RestoreDashboardCommand("1")
+        with pytest.raises(DashboardSlugConflictError):
+            cmd.run()
+
+    mock_twin_check.assert_called_once_with(dashboard)
+
+
+def test_restore_dashboard_no_slug_conflict_when_no_active_collision(
+    app_context: None,
+) -> None:
+    """No collision check fires when no other active dashboard has the same 
slug."""
+    from superset.commands.dashboard.restore import RestoreDashboardCommand
+
+    dashboard = MagicMock()
+    dashboard.deleted_at = datetime(2026, 1, 1, tzinfo=timezone.utc)
+    dashboard.slug = "q1-report"
+    dashboard.id = 42
+
+    with (
+        patch(
+            "superset.daos.dashboard.DashboardDAO.find_by_id", 
return_value=dashboard
+        ),
+        patch("superset.commands.restore.security_manager") as mock_sec,
+        patch.object(
+            RestoreDashboardCommand, "_has_active_slug_twin", 
return_value=False
+        ),
+    ):
+        mock_sec.raise_for_ownership.return_value = None
+
+        cmd = RestoreDashboardCommand("1")
+        cmd.run()
+
+    dashboard.restore.assert_called_once()
+
+
+def test_restore_dashboard_skips_conflict_check_when_no_slug(
+    app_context: None,
+) -> None:
+    """Dashboards without a slug skip the conflict check entirely."""
+    from superset.commands.dashboard.restore import RestoreDashboardCommand
+
+    dashboard = MagicMock()

Review Comment:
   **Suggestion:** Introduce an explicit type annotation for `dashboard` here 
to keep variable typing consistent with the enforced rule. [custom_rule]
   
   **Severity Level:** Minor ⚠️
   <details>
   <summary><b>Why it matters? 🤔 </b></summary>
   
   This is a new untyped Python local in the added test file. Since it can be 
annotated, it violates the stated type-hint rule.
   </details>
   
   [![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=611a06df5b654e2caff1ce2e165736da&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=611a06df5b654e2caff1ce2e165736da&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** tests/unit_tests/commands/dashboard/restore_test.py
   **Line:** 147:147
   **Comment:**
        *Custom Rule: Introduce an explicit type annotation for `dashboard` 
here to keep variable typing consistent with the enforced rule.
   
   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%2F40128&comment_hash=a44daca93775a8daac550a8aec38458ee32511c6c537f721bcfe299d061d68af&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40128&comment_hash=a44daca93775a8daac550a8aec38458ee32511c6c537f721bcfe299d061d68af&reaction=dislike'>👎</a>



##########
tests/unit_tests/commands/dashboard/restore_test.py:
##########
@@ -0,0 +1,201 @@
+# 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.
+"""Unit tests for RestoreDashboardCommand."""
+
+from __future__ import annotations
+
+from datetime import datetime, timezone
+from unittest.mock import MagicMock, patch
+
+import pytest
+
+
+def test_restore_dashboard_not_found_raises(app_context: None) -> None:
+    """RestoreDashboardCommand raises DashboardNotFoundError for missing 
dashboard."""
+    from superset.commands.dashboard.exceptions import DashboardNotFoundError
+    from superset.commands.dashboard.restore import RestoreDashboardCommand
+
+    with patch("superset.daos.dashboard.DashboardDAO.find_by_id", 
return_value=None):
+        cmd = RestoreDashboardCommand("999")
+        with pytest.raises(DashboardNotFoundError):
+            cmd.run()
+
+
+def test_restore_active_dashboard_raises_not_found(app_context: None) -> None:
+    """RestoreDashboardCommand raises DashboardNotFoundError for non-deleted 
dashboard."""  # noqa: E501
+    from superset.commands.dashboard.exceptions import DashboardNotFoundError
+    from superset.commands.dashboard.restore import RestoreDashboardCommand
+
+    dashboard = MagicMock()
+    dashboard.deleted_at = None  # not soft-deleted
+
+    with patch(
+        "superset.daos.dashboard.DashboardDAO.find_by_id", 
return_value=dashboard
+    ):
+        cmd = RestoreDashboardCommand("1")
+        with pytest.raises(DashboardNotFoundError):
+            cmd.run()
+
+
+def test_restore_dashboard_forbidden_raises(app_context: None) -> None:
+    """RestoreDashboardCommand raises DashboardForbiddenError on permission 
check."""
+    from superset.commands.dashboard.exceptions import DashboardForbiddenError
+    from superset.commands.dashboard.restore import RestoreDashboardCommand
+    from superset.exceptions import SupersetSecurityException
+
+    dashboard = MagicMock()
+    dashboard.deleted_at = datetime(2026, 1, 1, tzinfo=timezone.utc)
+
+    def raise_security(*args: object, **kwargs: object) -> None:
+        raise SupersetSecurityException(MagicMock())
+
+    with (
+        patch(
+            "superset.daos.dashboard.DashboardDAO.find_by_id", 
return_value=dashboard
+        ),
+        patch("superset.commands.restore.security_manager") as mock_sec,
+    ):
+        mock_sec.raise_for_ownership = raise_security
+
+        cmd = RestoreDashboardCommand("1")
+        with pytest.raises(DashboardForbiddenError):
+            cmd.run()
+
+
+def test_restore_dashboard_slug_conflict_raises(app_context: None) -> None:
+    """Restore raises DashboardSlugConflictError when slug is now claimed by 
an active dashboard.
+
+    The partial unique index ``WHERE deleted_at IS NULL`` allows another
+    dashboard to claim the slug while this one was soft-deleted. The
+    command catches that case before flushing so the operator sees a
+    domain-specific error instead of an opaque unique-index violation.
+    """  # noqa: E501
+    from superset.commands.dashboard.exceptions import 
DashboardSlugConflictError
+    from superset.commands.dashboard.restore import RestoreDashboardCommand
+
+    dashboard = MagicMock()

Review Comment:
   **Suggestion:** Provide a concrete type annotation for `dashboard` in this 
test case to satisfy the custom type-hint rule. [custom_rule]
   
   **Severity Level:** Minor ⚠️
   <details>
   <summary><b>Why it matters? 🤔 </b></summary>
   
   The variable is introduced without a type hint in new Python code, and it is 
the kind of relevant local variable the rule is meant to catch.
   </details>
   
   [![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=ac27d737911c4f1daceeb4f7e41e8fad&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=ac27d737911c4f1daceeb4f7e41e8fad&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** tests/unit_tests/commands/dashboard/restore_test.py
   **Line:** 90:90
   **Comment:**
        *Custom Rule: Provide a concrete type annotation for `dashboard` in 
this test case to satisfy the custom type-hint rule.
   
   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%2F40128&comment_hash=6dd3e37d26856e0f653472fce79093660520f4265d71b536e5493aca5f6e80dd&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40128&comment_hash=6dd3e37d26856e0f653472fce79093660520f4265d71b536e5493aca5f6e80dd&reaction=dislike'>👎</a>



##########
superset/models/dashboard.py:
##########
@@ -141,7 +145,13 @@ class Dashboard(CoreDashboard, AuditMixinNullable, 
ImportExportMixin):
     certified_by = Column(Text)
     certification_details = Column(Text)
     json_metadata = Column(utils.MediumText())
-    slug = Column(String(255), unique=True)
+    # Slug uniqueness is enforced via a partial unique index
+    # (``ix_dashboards_active_slug WHERE deleted_at IS NULL``) on
+    # PostgreSQL and MySQL 8.0+, so soft-deleted rows do not reserve
+    # their slug. SQLite and MySQL <8.0 keep the original full unique
+    # constraint via the migration; on those dialects slug reservation
+    # persists across soft-delete. See the 9e1f3b8c4d2a migration for details.
+    slug = Column(String(255))

Review Comment:
   **Suggestion:** Add an explicit type annotation to this newly added model 
attribute to comply with the type-hint requirement for relevant variables. 
[custom_rule]
   
   **Severity Level:** Minor ⚠️
   <details>
   <summary><b>Why it matters? 🤔 </b></summary>
   
   The new model field is introduced without any type annotation even though it 
is a relevant variable that can be annotated, so this matches the type-hint 
requirement.
   </details>
   
   [![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=d71ae7b3157f45e28726e64d75d0f05c&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=d71ae7b3157f45e28726e64d75d0f05c&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset/models/dashboard.py
   **Line:** 154:154
   **Comment:**
        *Custom Rule: Add an explicit type annotation to this newly added model 
attribute to comply with the type-hint requirement for relevant variables.
   
   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%2F40128&comment_hash=5a7d9acfe2790374efa6b620950ebe9893c7fbd8acf22c1c130f0dda10fa0751&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40128&comment_hash=5a7d9acfe2790374efa6b620950ebe9893c7fbd8acf22c1c130f0dda10fa0751&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