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


##########
superset/commands/chart/exceptions.py:
##########
@@ -123,6 +123,16 @@ class ChartDeleteFailedError(DeleteFailedError):
     message = _("Charts could not be deleted.")
 
 
+class ChartRestoreFailedError(UpdateFailedError):
+    # Restore semantically clears ``deleted_at``; it is an UPDATE, not a new
+    # row. ``UpdateFailedError`` is the nearest typed middle-tier base in the
+    # codebase. A dedicated ``RestoreFailedError`` in
+    # ``superset/commands/exceptions.py`` would be more precise across the
+    # entity rollouts but lives in already-merged infrastructure (#39977);
+    # introducing it can be a cross-entity follow-up.
+    message = _("Chart could not be restored.")

Review Comment:
   **Suggestion:** Add a class docstring to this newly introduced exception 
class to satisfy the requirement that new Python classes are documented inline. 
[custom_rule]
   
   **Severity Level:** Minor ⚠️
   <details>
   <summary><b>Why it matters? 🤔 </b></summary>
   
   This is a newly added Python class and it does not include a docstring. The
   class only has comments and a class attribute, so it violates the rule that
   new classes should be documented inline.
   </details>
   
   [Fix in 
Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=5bc6e1c5e1a04ce7b9d3d4a8299659ce&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 | [Fix in VSCode 
Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=5bc6e1c5e1a04ce7b9d3d4a8299659ce&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/commands/chart/exceptions.py
   **Line:** 126:133
   **Comment:**
        *Custom Rule: Add a class docstring to this newly introduced exception 
class to satisfy the requirement that new Python classes are documented inline.
   
   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%2F40129&comment_hash=bce5c5c38a3f8880742fd5557f31c35e422d84de590377c48fdd975ed161f135&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40129&comment_hash=bce5c5c38a3f8880742fd5557f31c35e422d84de590377c48fdd975ed161f135&reaction=dislike'>👎</a>



##########
tests/unit_tests/commands/chart/restore_test.py:
##########
@@ -0,0 +1,90 @@
+# 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 RestoreChartCommand."""
+
+from __future__ import annotations
+
+from datetime import datetime, timezone
+from unittest.mock import MagicMock, patch
+
+import pytest
+
+from superset.commands.chart.exceptions import (
+    ChartForbiddenError,
+    ChartNotFoundError,
+)
+from superset.commands.chart.restore import RestoreChartCommand
+from superset.exceptions import SupersetSecurityException
+
+
+def test_restore_chart_clears_deleted_at(app_context: None) -> None:
+    """RestoreChartCommand.run() restores a soft-deleted chart."""
+    chart = MagicMock()
+    chart.deleted_at = datetime(2026, 1, 1, tzinfo=timezone.utc)
+    chart.id = 1
+
+    with (
+        patch(
+            "superset.daos.chart.ChartDAO.find_by_id", return_value=chart
+        ) as mock_find,
+        patch("superset.commands.restore.security_manager") as mock_sec,
+    ):
+        mock_sec.raise_for_ownership.return_value = None
+
+        cmd = RestoreChartCommand("1")
+        cmd.run()
+
+    mock_find.assert_called_once()
+    chart.restore.assert_called_once()
+
+
+def test_restore_chart_not_found_raises(app_context: None) -> None:
+    """RestoreChartCommand raises ChartNotFoundError for missing chart."""
+    with patch("superset.daos.chart.ChartDAO.find_by_id", return_value=None):
+        cmd = RestoreChartCommand("999")
+        with pytest.raises(ChartNotFoundError):
+            cmd.run()
+
+
+def test_restore_active_chart_raises_not_found(app_context: None) -> None:
+    """RestoreChartCommand raises ChartNotFoundError for non-deleted chart."""
+    chart = MagicMock()
+    chart.deleted_at = None  # not soft-deleted
+
+    with patch("superset.daos.chart.ChartDAO.find_by_id", return_value=chart):
+        cmd = RestoreChartCommand("1")
+        with pytest.raises(ChartNotFoundError):
+            cmd.run()
+
+
+def test_restore_chart_forbidden_raises(app_context: None) -> None:
+    """RestoreChartCommand raises ChartForbiddenError on permission check."""
+    chart = MagicMock()
+    chart.deleted_at = datetime(2026, 1, 1, tzinfo=timezone.utc)
+
+    def raise_security(*args: object, **kwargs: object) -> None:
+        raise SupersetSecurityException(MagicMock())

Review Comment:
   **Suggestion:** Add an inline docstring to the newly introduced helper 
function so that all new functions in this file are documented. [custom_rule]
   
   **Severity Level:** Minor ⚠️
   <details>
   <summary><b>Why it matters? 🤔 </b></summary>
   
   This is a newly introduced function in the added test file, and it does not 
have a docstring. The custom rule explicitly requires newly added Python 
functions and classes to include docstrings, so this is a real violation.
   </details>
   
   [Fix in 
Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=66b68a1f2120404886cdfcd2329ed8a1&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 | [Fix in VSCode 
Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=66b68a1f2120404886cdfcd2329ed8a1&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/chart/restore_test.py
   **Line:** 79:80
   **Comment:**
        *Custom Rule: Add an inline docstring to the newly introduced helper 
function so that all new functions in this file are documented.
   
   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%2F40129&comment_hash=65d45d6cc3b05a87c1308f350ea8ded8a29225f27ff3242ffebb54b43e14deb6&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40129&comment_hash=65d45d6cc3b05a87c1308f350ea8ded8a29225f27ff3242ffebb54b43e14deb6&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