This is an automated email from the ASF dual-hosted git repository.

aminghadersohi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/master by this push:
     new ea58fc9669e fix(dataset): scope Usage charts by datasource type 
(#46258)
ea58fc9669e is described below

commit ea58fc9669ecc169f62b044f52d9a0973cd79222
Author: Mike Bridge <[email protected]>
AuthorDate: Tue Nov 17 17:36:31 2026 -0600

    fix(dataset): scope Usage charts by datasource type (#46258)
---
 .../DatasourceEditor/DatasourceEditor.tsx          | 12 ++++-
 .../tests/DatasourceEditor.test.tsx                | 61 ++++++++++++++++++++++
 tests/unit_tests/charts/test_filters.py            | 38 ++++++++++----
 3 files changed, 101 insertions(+), 10 deletions(-)

diff --git 
a/superset-frontend/src/components/Datasource/components/DatasourceEditor/DatasourceEditor.tsx
 
b/superset-frontend/src/components/Datasource/components/DatasourceEditor/DatasourceEditor.tsx
index 94ccc8b4d04..2496db84b37 100644
--- 
a/superset-frontend/src/components/Datasource/components/DatasourceEditor/DatasourceEditor.tsx
+++ 
b/superset-frontend/src/components/Datasource/components/DatasourceEditor/DatasourceEditor.tsx
@@ -1986,6 +1986,11 @@ function DatasourceEditor({
               opr: 'eq',
               value: datasource.id,
             },
+            {
+              col: 'datasource_type',
+              opr: 'eq',
+              value: datasource.datasource_type || datasource.type,
+            },
           ],
           order_column: sortColumn,
           order_direction: sortDirection,
@@ -2042,7 +2047,12 @@ function DatasourceEditor({
         abortControllers.current.fetchUsageData = null;
       }
     },
-    [datasource.id, addDangerToast],
+    [
+      datasource.id,
+      datasource.datasource_type,
+      datasource.type,
+      addDangerToast,
+    ],
   );
 
   const handleTabSelect = useCallback((key: string) => {
diff --git 
a/superset-frontend/src/components/Datasource/components/DatasourceEditor/tests/DatasourceEditor.test.tsx
 
b/superset-frontend/src/components/Datasource/components/DatasourceEditor/tests/DatasourceEditor.test.tsx
index 3cacd37f2a2..854810256cf 100644
--- 
a/superset-frontend/src/components/Datasource/components/DatasourceEditor/tests/DatasourceEditor.test.tsx
+++ 
b/superset-frontend/src/components/Datasource/components/DatasourceEditor/tests/DatasourceEditor.test.tsx
@@ -17,6 +17,7 @@
  * under the License.
  */
 import fetchMock from 'fetch-mock';
+import rison from 'rison';
 import {
   fireEvent,
   screen,
@@ -71,6 +72,66 @@ test('renders Tabs', async () => {
   expect(screen.getByTestId('edit-dataset-tabs')).toBeInTheDocument();
 });
 
+test('Usage excludes semantic-view charts whose datasource id matches the 
dataset', async () => {
+  const testProps = createProps();
+  const charts = [
+    {
+      id: 101,
+      slice_name: 'Dataset chart',
+      datasource_id: testProps.datasource.id,
+      datasource_type: DatasourceType.Table,
+    },
+    {
+      id: 102,
+      slice_name: 'Semantic view chart',
+      datasource_id: testProps.datasource.id,
+      datasource_type: DatasourceType.SemanticView,
+    },
+    {
+      id: 103,
+      slice_name: 'Other dataset chart',
+      datasource_id: testProps.datasource.id + 1,
+      datasource_type: DatasourceType.Table,
+    },
+  ];
+  fetchMock.removeRoutes();
+  fetchMock.get(DATASOURCE_ENDPOINT, []);
+  fetchMock.get('glob:*/api/v1/chart/*', ({ url }) => {
+    const { filters } = rison.decode<{
+      filters: {
+        col: 'datasource_id' | 'datasource_type';
+        opr: string;
+        value: string | number;
+      }[];
+    }>(new URL(url, 'http://localhost').searchParams.get('q') ?? '');
+    const matches = charts.filter(chart =>
+      filters.every(filter => chart[filter.col] === filter.value),
+    );
+    return {
+      count: matches.length,
+      ids: matches.map(chart => chart.id),
+      result: matches.map(chart => ({
+        ...chart,
+        url: `/explore/?slice_id=${chart.id}`,
+        changed_on_delta_humanized: 'a day ago',
+        changed_by: null,
+        dashboards: [],
+      })),
+    };
+  });
+  setupDatasourceEditorMocks();
+
+  await asyncRender(testProps);
+  await userEvent.click(screen.getByRole('tab', { name: /usage/i }));
+
+  expect(
+    await screen.findByRole('link', { name: 'Dataset chart' }),
+  ).toBeVisible();
+  expect(screen.queryByText('Semantic view chart')).not.toBeInTheDocument();
+  expect(screen.queryByText('Other dataset chart')).not.toBeInTheDocument();
+  expect(screen.getByRole('tab', { name: /usage/i })).toHaveTextContent('1');
+});
+
 test('recommends a registered client route for the default URL', async () => {
   await asyncRender(createProps());
 
diff --git a/tests/unit_tests/charts/test_filters.py 
b/tests/unit_tests/charts/test_filters.py
index 92ba93f44d3..44a137f9476 100644
--- a/tests/unit_tests/charts/test_filters.py
+++ b/tests/unit_tests/charts/test_filters.py
@@ -85,11 +85,33 @@ def 
test_chart_datasource_filter_rejects_malformed_identity(identity: object) ->
 
 
 @pytest.mark.parametrize(
-    "identity, expected",
+    "filters, expected",
     [
-        (7, "table chart"),
-        ("7__table", "table chart"),
-        ("7__semantic_view", "semantic chart"),
+        (
+            [{"col": "datasource_id", "opr": "chart_datasource", "value": 7}],
+            "table chart",
+        ),
+        (
+            [{"col": "datasource_id", "opr": "chart_datasource", "value": 
"7__table"}],
+            "table chart",
+        ),
+        (
+            [
+                {
+                    "col": "datasource_id",
+                    "opr": "chart_datasource",
+                    "value": "7__semantic_view",
+                }
+            ],
+            "semantic chart",
+        ),
+        (
+            [
+                {"col": "datasource_id", "opr": "eq", "value": 7},
+                {"col": "datasource_type", "opr": "eq", "value": "table"},
+            ],
+            "table chart",
+        ),
     ],
 )
 def test_chart_list_datasource_identity(
@@ -98,10 +120,10 @@ def test_chart_list_datasource_identity(
     mocker: MockerFixture,
     session: Session,
     semantic_layers_enabled: None,
-    identity: int | str,
+    filters: list[dict[str, str | int]],
     expected: str,
 ) -> None:
-    """The registered list operator separates same-ID sources and accepts old 
links."""
+    """Registered list operators separate same-ID sources and accept old 
links."""
     # Avoid app-init imports: models and API registration need the app fixture.
     from superset.charts.api import ChartRestApi
     from superset.models.slice import Slice
@@ -122,9 +144,7 @@ def test_chart_list_datasource_identity(
     query: str = prison.dumps(
         {
             "columns": ["id", "slice_name"],
-            "filters": [
-                {"col": "datasource_id", "opr": "chart_datasource", "value": 
identity}
-            ],
+            "filters": filters,
         }
     )
     response: TestResponse = client.get("/api/v1/chart/", query_string={"q": 
query})

Reply via email to