codeant-ai-for-open-source[bot] commented on code in PR #40129:
URL: https://github.com/apache/superset/pull/40129#discussion_r3510307709
##########
superset/charts/filters.py:
##########
@@ -196,3 +197,40 @@ def apply(self, query: Query, value: Any) -> Query:
FavStar.user_id == get_user_id(),
)
)
+
+
+class ChartDeletedStateFilter( # pylint: disable=too-few-public-methods
+ BaseDeletedStateFilter
+):
+ """Rison filter for the GET list that exposes soft-deleted charts.
+
+ Soft-deleted rows are additionally scoped to the **restore audience**: only
+ the chart's owners (or admins) may enumerate them. This mirrors
+ ``RestoreChartCommand``'s ``raise_for_ownership`` check, so a read-access
+ non-owner (who can see the chart via datasource access) cannot list
+ soft-deleted charts they could never restore. Live rows are unaffected —
+ they keep their normal ``ChartFilter`` visibility. The ownership scoping is
+ part of the cross-entity deleted-state contract: only the restore audience
+ may enumerate soft-deleted rows (kept consistent with the deleted-state
+ filters in the dashboard and dataset soft-delete rollouts).
+ """
+
+ arg_name = "chart_deleted_state"
+ model = Slice
+
+ def apply(self, query: Query, value: Any) -> Query:
Review Comment:
✅ **Customized review instruction saved!**
**Instruction:**
> Do not require method-level docstrings when the enclosing class docstring
already documents the behavior; avoid duplicating the same explanation.
**Applied to:**
- `superset/charts/**`
---
💡 *To manage or update this instruction, visit: [CodeAnt AI
Settings](https://app.codeant.ai/org/settings/learnings)*
##########
superset/daos/dashboard.py:
##########
@@ -276,8 +277,19 @@ def set_dash_metadata(
if isinstance(value, dict)
]
+ # Bypass the soft-delete visibility filter when resolving the
+ # incoming chart ids: a dashboard's ``position_json`` may still
+ # reference a chart that is currently soft-deleted, and this
+ # assignment REBUILDS ``dashboard.slices`` wholesale. With the
+ # filter active, the hidden member would be silently dropped —
+ # deleting its ``dashboard_slices`` junction row (breaking the
+ # documented restore-reattach contract) and writing
+ # ``uuid: None`` into its position slot via ``uuid_map`` below.
current_slices = (
- db.session.query(Slice).filter(Slice.id.in_(slice_ids)).all()
+ db.session.query(Slice)
+ .execution_options(**{SKIP_VISIBILITY_FILTER_CLASSES: {Slice}})
+ .filter(Slice.id.in_(slice_ids))
+ .all()
)
Review Comment:
✅ **Customized review instruction saved!**
**Instruction:**
> Do not require explicit type annotations for local variables in Python
when the type is obvious from surrounding context and the file already follows
that convention.
**Applied to:**
- `superset/daos/**`
---
💡 *To manage or update this instruction, visit: [CodeAnt AI
Settings](https://app.codeant.ai/org/settings/learnings)*
##########
tests/integration_tests/charts/commands_tests.py:
##########
@@ -721,7 +721,7 @@ def test_fave_unfave_chart_command(self):
def test_fave_unfave_chart_command_not_found(self):
"""Test that faving / unfaving a non-existing chart raises an
exception"""
with self.client.application.test_request_context():
- example_chart_id = 1234
+ example_chart_id = 0
Review Comment:
✅ **Customized review instruction saved!**
**Instruction:**
> Do not require explicit type annotations for simple local/test-scaffolding
variables when the type is obvious from context.
**Applied to:**
- `**/test/**`
- `**/tests/**`
- `**/*test*.py`
---
💡 *To manage or update this instruction, visit: [CodeAnt AI
Settings](https://app.codeant.ai/org/settings/learnings)*
##########
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")
Review Comment:
✅ **Customized review instruction saved!**
**Instruction:**
> Do not flag missing type annotations for local test-scaffolding variables
when the type is already unambiguous from context.
**Applied to:**
- `**/test/**`
- `**/tests/**`
- `**/*test*.py`
---
💡 *To manage or update this instruction, visit: [CodeAnt AI
Settings](https://app.codeant.ai/org/settings/learnings)*
--
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]