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


##########
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")

Review Comment:
   **Suggestion:** Add an explicit type annotation for this command variable so 
the newly introduced local variable is fully typed. [custom_rule]
   
   **Severity Level:** Minor ⚠️
   <details>
   <summary><b>Why it matters? 🤔 </b></summary>
   
   This local variable is introduced in new Python code without a type hint, 
and it is a straightforward candidate for annotation. That is a real violation 
of the 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=cfbb54b283a045bfa2590c4e8cf218dd&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=cfbb54b283a045bfa2590c4e8cf218dd&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:** 48:48
   **Comment:**
        *Custom Rule: Add an explicit type annotation for this command variable 
so the newly introduced local variable is fully typed.
   
   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=152e9b504d6fa9a51e36fa7f1aff66806587997a1e8a7d9554888d52c8e0d78b&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40129&comment_hash=152e9b504d6fa9a51e36fa7f1aff66806587997a1e8a7d9554888d52c8e0d78b&reaction=dislike'>👎</a>



##########
tests/unit_tests/dao/dashboard_test.py:
##########
@@ -0,0 +1,95 @@
+# 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.
+from datetime import datetime, timezone
+from typing import Any
+
+from sqlalchemy.orm.session import Session
+
+
+def test_set_dash_metadata_preserves_soft_deleted_members(
+    session: Session,
+) -> None:
+    """Saving a dashboard must not sever a soft-deleted member chart.
+
+    ``set_dash_metadata`` rebuilds ``dashboard.slices`` wholesale from the
+    incoming position data. The slice-resolution query must bypass the
+    soft-delete visibility filter: with the filter active, a member chart
+    sitting in the trash would be silently dropped from the assignment —
+    deleting its ``dashboard_slices`` junction row (breaking the
+    restore-reattach contract) and writing ``uuid: None`` into its
+    position slot. This test fails if the bypass is removed.
+    """
+    from superset import db
+    from superset.connectors.sqla.models import Database, SqlaTable
+    from superset.daos.dashboard import DashboardDAO
+    from superset.models.dashboard import Dashboard
+    from superset.models.slice import Slice
+
+    Dashboard.metadata.create_all(session.get_bind())
+
+    dataset = SqlaTable(
+        table_name="dash_meta_table",
+        database=Database(database_name="dash_meta_db", 
sqlalchemy_uri="sqlite://"),
+    )
+    db.session.add(dataset)
+    db.session.flush()
+
+    live_chart = Slice(
+        slice_name="live_chart",
+        datasource_id=dataset.id,
+        datasource_type="table",
+    )
+    trashed_chart = Slice(
+        slice_name="trashed_chart",
+        datasource_id=dataset.id,
+        datasource_type="table",
+        deleted_at=datetime(2026, 1, 1, tzinfo=timezone.utc),
+    )
+    dashboard = Dashboard(
+        dashboard_title="meta_test_dash",
+        slices=[live_chart, trashed_chart],
+        published=True,
+    )
+    db.session.add_all([live_chart, trashed_chart, dashboard])
+    db.session.flush()
+
+    positions: dict[str, dict[str, Any]] = {
+        "CHART-live": {
+            "type": "CHART",
+            "id": "CHART-live",
+            "children": [],
+            "meta": {"chartId": live_chart.id, "width": 4, "height": 50},
+        },
+        "CHART-trashed": {
+            "type": "CHART",
+            "id": "CHART-trashed",
+            "children": [],
+            "meta": {"chartId": trashed_chart.id, "width": 4, "height": 50},
+        },
+    }
+
+    DashboardDAO.set_dash_metadata(dashboard, {"positions": positions})
+
+    member_ids = {chart.id for chart in dashboard.slices}

Review Comment:
   **Suggestion:** Add an explicit type annotation for `member_ids` to satisfy 
the type-hints requirement for relevant newly introduced variables. 
[custom_rule]
   
   **Severity Level:** Minor ⚠️
   <details>
   <summary><b>Why it matters? 🤔 </b></summary>
   
   The file is new Python code, and `member_ids` is an unannotated variable 
whose type can clearly be expressed. This matches the rule requiring type hints 
on relevant variables in new or modified Python code.
   </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=ce6bdac9122944d7ae86cdb914c12b9a&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=ce6bdac9122944d7ae86cdb914c12b9a&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/dao/dashboard_test.py
   **Line:** 87:87
   **Comment:**
        *Custom Rule: Add an explicit type annotation for `member_ids` to 
satisfy the type-hints requirement for relevant newly introduced 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%2F40129&comment_hash=b1eee493a8005448b3662a1a0fcd4a7341d39e626cd3324247957679f46087dc&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40129&comment_hash=b1eee493a8005448b3662a1a0fcd4a7341d39e626cd3324247957679f46087dc&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()

Review Comment:
   **Suggestion:** Add an explicit type annotation for this mocked chart 
variable in the permission test to comply with the type-hint rule. [custom_rule]
   
   **Severity Level:** Minor ⚠️
   <details>
   <summary><b>Why it matters? 🤔 </b></summary>
   
   This is another untyped local variable in the added Python test code. Since 
it can be annotated, the suggestion correctly identifies a type-hint violation.
   </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=7e21c5e5b8c842849f2121714cec5fc1&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=7e21c5e5b8c842849f2121714cec5fc1&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:** 76:76
   **Comment:**
        *Custom Rule: Add an explicit type annotation for this mocked chart 
variable in the permission test to comply with the 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%2F40129&comment_hash=0e528e65a9acd389710997c0e741588fc246c61606940388854125a5ae915005&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40129&comment_hash=0e528e65a9acd389710997c0e741588fc246c61606940388854125a5ae915005&reaction=dislike'>👎</a>



##########
tests/unit_tests/migrations/test_add_deleted_at_to_slices.py:
##########
@@ -0,0 +1,186 @@
+# 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.
+"""Tests for migration ``7c4a8d09ca37_add_deleted_at_to_slices``.
+
+Runs the migration's ``upgrade()`` and ``downgrade()`` against an
+in-memory SQLite engine with a real Alembic ``Operations`` context.
+The behaviour being pinned is the operator-facing contract documented
+in ``UPDATING.md``: ``downgrade()`` reverses the schema but does not
+hard-delete or otherwise mutate rows that were soft-deleted before
+the migration was reversed — those rows survive the downgrade and
+become visible to any code path that no longer applies the
+soft-delete visibility filter.
+"""
+
+from __future__ import annotations
+
+from datetime import datetime
+from importlib import import_module
+
+import pytest
+from alembic.migration import MigrationContext
+from alembic.operations import Operations
+from sqlalchemy import (
+    Column,
+    create_engine,
+    insert,
+    inspect,
+    Integer,
+    MetaData,
+    select,
+    String,
+    Table,
+)
+from sqlalchemy.engine import Engine
+
+migration = import_module(
+    "superset.migrations.versions."
+    "2026-05-08_12-00_7c4a8d09ca37_add_deleted_at_to_slices"
+)

Review Comment:
   **Suggestion:** Add an explicit type annotation for the dynamically imported 
`migration` module so this new variable is fully typed. [custom_rule]
   
   **Severity Level:** Minor ⚠️
   <details>
   <summary><b>Why it matters? 🤔 </b></summary>
   
   This new module-level variable is inferred without an explicit type hint, 
and it is a relevant annotatable variable under the Python type-hint rule. The 
suggestion correctly identifies a real omission.
   </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=97f1862880c44b888cee0680ddcd7052&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=97f1862880c44b888cee0680ddcd7052&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/migrations/test_add_deleted_at_to_slices.py
   **Line:** 50:53
   **Comment:**
        *Custom Rule: Add an explicit type annotation for the dynamically 
imported `migration` module so this new variable is fully typed.
   
   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=17b464f5bf9f9b1a097a25bdd05f6bc3752582f24df83daa0e4345ffa8c0c546&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40129&comment_hash=17b464f5bf9f9b1a097a25bdd05f6bc3752582f24df83daa0e4345ffa8c0c546&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