You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ru...@apache.org on 2026/09/10 21:00:26 UTC

(superset) branch fix/table-v2-import-feature-flag-gate created (now 1861981a147)

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

rusackas pushed a change to branch fix/table-v2-import-feature-flag-gate
in repository https://gitbox.apache.org/repos/asf/superset.git


      at 1861981a147 fix(charts): don't auto-migrate table charts to ag-grid-table on import unless enabled

This branch includes the following new commits:

     new 1861981a147 fix(charts): don't auto-migrate table charts to ag-grid-table on import unless enabled

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(superset) 01/01: fix(charts): don't auto-migrate table charts to ag-grid-table on import unless enabled

Posted by ru...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rusackas pushed a commit to branch fix/table-v2-import-feature-flag-gate
in repository https://gitbox.apache.org/repos/asf/superset.git

commit 1861981a1473475114c8bc94a5909bf01fc71a71
Author: Evan Rusackas <ev...@rusackas.com>
AuthorDate: Thu Sep 10 13:59:44 2026 -0700

    fix(charts): don't auto-migrate table charts to ag-grid-table on import unless enabled
    
    migrate_chart() (used by both example loading and the chart import API)
    unconditionally converted any imported viz_type: table chart's target,
    regardless of AG_GRID_TABLE_ENABLED. Since that flag is off by default and
    ag-grid-table's frontend plugin is only registered when it's on, every
    fresh install running `superset load_examples` got charts whose stored
    viz_type the running frontend can't render at all ("Item with key
    ag-grid-table is not registered"), affecting at least seven of the bundled
    example dashboards.
    
    Add MigrateViz.requires_feature_flag and check it only in the importer path
    (superset/cli/viz_migrations.py's `migrate_viz` CLI is unaffected --
    invoking it is already the deliberate opt-in the flag exists to gate).
---
 superset/commands/chart/importers/v1/utils.py      | 12 ++++-
 superset/migrations/shared/migrate_viz/base.py     |  7 +++
 .../migrations/shared/migrate_viz/processors.py    |  6 +++
 .../charts/commands/importers/v1/utils_test.py     | 62 ++++++++++++++++++++++
 4 files changed, 86 insertions(+), 1 deletion(-)

diff --git a/superset/commands/chart/importers/v1/utils.py b/superset/commands/chart/importers/v1/utils.py
index 20e59cb2397..e299b28c277 100644
--- a/superset/commands/chart/importers/v1/utils.py
+++ b/superset/commands/chart/importers/v1/utils.py
@@ -25,6 +25,7 @@ from superset.commands.importers.v1.utils import (
     apply_extra_import_fields,
     find_existing_for_import,
 )
+from superset.extensions import feature_flag_manager
 from superset.migrations.shared.migrate_viz import processors
 from superset.migrations.shared.migrate_viz.base import MigrateViz
 from superset.models.slice import Slice
@@ -252,7 +253,16 @@ def migrate_chart(config: dict[str, Any]) -> dict[str, Any]:
     if config["viz_type"] not in migrators:
         return output
 
-    migrator = migrators[config["viz_type"]](output["params"])
+    migrator_class = migrators[config["viz_type"]]
+    required_flag = migrator_class.requires_feature_flag
+    # Importing a chart isn't itself an opt-in to a target viz type that's
+    # still gated off by default (see MigrateViz.requires_feature_flag) --
+    # leave the chart as its original viz_type rather than silently handing
+    # back one the frontend may not have registered.
+    if required_flag and not feature_flag_manager.is_feature_enabled(required_flag):
+        return output
+
+    migrator = migrator_class(output["params"])
     # pylint: disable=protected-access
     migrator._pre_action()
     migrator._migrate()
diff --git a/superset/migrations/shared/migrate_viz/base.py b/superset/migrations/shared/migrate_viz/base.py
index 7b84056f71d..cfe7a4a6ff0 100644
--- a/superset/migrations/shared/migrate_viz/base.py
+++ b/superset/migrations/shared/migrate_viz/base.py
@@ -62,6 +62,13 @@ class MigrateViz:
     source_viz_type: str
     target_viz_type: str
     has_x_axis_control: bool = False
+    # When set, the *import* path (superset/commands/chart/importers/v1/
+    # utils.py::migrate_chart) only applies this migration while the named
+    # feature flag is on, since importing a chart isn't itself an opt-in to
+    # a still-`IN DEVELOPMENT` target viz type the way running the
+    # `migrate_viz` CLI is. The CLI (superset/cli/viz_migrations.py) ignores
+    # this: invoking it is already the deliberate opt-in.
+    requires_feature_flag: str | None = None
 
     def __init__(self, form_data: str) -> None:
         self.data = try_load_json(form_data)
diff --git a/superset/migrations/shared/migrate_viz/processors.py b/superset/migrations/shared/migrate_viz/processors.py
index 2f48fd8c47c..96be6292a1d 100644
--- a/superset/migrations/shared/migrate_viz/processors.py
+++ b/superset/migrations/shared/migrate_viz/processors.py
@@ -767,6 +767,12 @@ def _get_table_chart_totals_metrics(
 class MigrateTableChart(MigrateViz):
     source_viz_type = "table"
     target_viz_type = "ag-grid-table"
+    # Table V2 is still `IN DEVELOPMENT`, gated behind AG_GRID_TABLE_ENABLED.
+    # Without this, importing any `table` chart (e.g. `load_examples` on a
+    # fresh install with the flag at its default False) would silently turn
+    # it into an ag-grid-table chart the frontend can't render at all: "Item
+    # with key ag-grid-table is not registered."
+    requires_feature_flag = "AG_GRID_TABLE_ENABLED"
     # allow_rearrange_columns/allow_render_html are kept as-is: v2 reads them
     # under the same names (see rename_keys below), so nothing to remove.
     # (allow_rearrange_columns still gets a value materialized in
diff --git a/tests/unit_tests/charts/commands/importers/v1/utils_test.py b/tests/unit_tests/charts/commands/importers/v1/utils_test.py
index 3770cd0d4d1..e0a4050c6f7 100644
--- a/tests/unit_tests/charts/commands/importers/v1/utils_test.py
+++ b/tests/unit_tests/charts/commands/importers/v1/utils_test.py
@@ -15,7 +15,12 @@
 # specific language governing permissions and limitations
 # under the License.
 
+from typing import Any
+
+from pytest_mock import MockerFixture
+
 from superset.commands.chart.importers.v1.utils import migrate_chart
+from superset.extensions import feature_flag_manager
 from superset.utils import json
 
 
@@ -212,3 +217,60 @@ def test_migrate_chart_query_context_form_data_is_dict() -> None:
 
     assert query_context["form_data"]["viz_type"] == "pivot_table_v2"
     assert isinstance(query_context["form_data"], dict)
+
+
+def _table_chart_config() -> dict[str, Any]:
+    return {
+        "slice_name": "Games",
+        "description": None,
+        "certified_by": None,
+        "certification_details": None,
+        "viz_type": "table",
+        "query_context": None,
+        "params": json.dumps(
+            {
+                "datasource": "1__table",
+                "viz_type": "table",
+                "query_mode": "aggregate",
+                "groupby": ["name"],
+                "metrics": ["count"],
+                "row_limit": 1000,
+            }
+        ),
+        "cache_timeout": None,
+        "uuid": "2a5e562b-ab37-1b9b-1de3-1be4335c8e83",
+        "version": "1.0.0",
+        "dataset_uuid": "a18b9cb0-b8d3-42ed-bd33-0f0fadbf0f6d",
+    }
+
+
+def test_migrate_chart_table_leaves_viz_type_unchanged_by_default() -> None:
+    """
+    Table V2 (``ag-grid-table``) is gated behind ``AG_GRID_TABLE_ENABLED``,
+    off by default. Importing a ``table`` chart -- e.g. ``load_examples`` on
+    a fresh install -- must not silently hand back an ag-grid-table chart
+    the frontend hasn't registered the plugin for.
+    """
+    chart_config = _table_chart_config()
+
+    new_config = migrate_chart(chart_config)
+
+    assert new_config == chart_config
+
+
+def test_migrate_chart_table_migrates_when_flag_enabled(
+    mocker: MockerFixture,
+) -> None:
+    """With the flag on, importing a `table` chart migrates it to v2, same
+    as any other viz migration."""
+    mocker.patch.object(
+        feature_flag_manager,
+        "is_feature_enabled",
+        side_effect=lambda flag: flag == "AG_GRID_TABLE_ENABLED",
+    )
+    chart_config = _table_chart_config()
+
+    new_config = migrate_chart(chart_config)
+
+    assert new_config["viz_type"] == "ag-grid-table"
+    assert json.loads(new_config["params"])["viz_type"] == "ag-grid-table"