fix: Adjust viz migrations to also migrate the queries object (#33285)

Co-authored-by: Michael S. Molina <michael.s.molina@gmail.com>
Co-authored-by: Michael S. Molina <70410625+michael-s-molina@users.noreply.github.com>
(cherry picked from commit 57183da315)
This commit is contained in:
Luiz Otavio
2025-05-26 15:00:07 -03:00
committed by Michael Molina
parent 685b259f6f
commit cfba5cdc57
11 changed files with 1887 additions and 107 deletions

View File

@@ -30,6 +30,7 @@ ADHOC_FILTERS = [
]
SOURCE_FORM_DATA: dict[str, Any] = {
"datasource": "1__table",
"metric": "num_boys",
"y_axis_format": ",d",
"y_axis_bounds": [50, 100],
@@ -44,6 +45,7 @@ SOURCE_FORM_DATA: dict[str, Any] = {
}
TARGET_FORM_DATA: dict[str, Any] = {
"datasource": "1__table",
"metrics": ["num_boys"],
"y_axis_format": ",d",
"y_axis_bounds": [50, 100],

View File

@@ -20,10 +20,15 @@ from superset.migrations.shared.migrate_viz import MigrateHeatmapChart
from tests.unit_tests.migrations.viz.utils import migrate_and_assert
SOURCE_FORM_DATA: dict[str, Any] = {
"datasource": "1__table",
"any_other_key": "untouched",
"all_columns_x": ["category"],
"all_columns_y": ["product"],
"metric": ["sales"],
"all_columns_x": "category",
"all_columns_y": "product",
"metric": {
"label": "sales",
"expressionType": "SQL",
"sqlExpression": "max(sales)",
},
"adhoc_filters": [],
"row_limit": 100,
"sort_by_metric": True,
@@ -47,10 +52,15 @@ SOURCE_FORM_DATA: dict[str, Any] = {
}
TARGET_FORM_DATA: dict[str, Any] = {
"datasource": "1__table",
"any_other_key": "untouched",
"x_axis": ["category"],
"groupby": ["product"],
"metric": ["sales"],
"x_axis": "category",
"groupby": "product",
"metric": {
"label": "sales",
"expressionType": "SQL",
"sqlExpression": "max(sales)",
},
"adhoc_filters": [],
"row_limit": 100,
"legend_type": "continuous",

View File

@@ -20,6 +20,7 @@ from superset.migrations.shared.migrate_viz import MigrateHistogramChart
from tests.unit_tests.migrations.viz.utils import migrate_and_assert
SOURCE_FORM_DATA: dict[str, Any] = {
"datasource": "1__table",
"all_columns_x": ["category"],
"adhoc_filters": [],
"cumulative": True,
@@ -33,6 +34,7 @@ SOURCE_FORM_DATA: dict[str, Any] = {
}
TARGET_FORM_DATA: dict[str, Any] = {
"datasource": "1__table",
"adhoc_filters": [],
"bins": 5,
"column": "category",

View File

@@ -20,6 +20,7 @@ from superset.migrations.shared.migrate_viz import MigrateBubbleChart
from tests.unit_tests.migrations.viz.utils import migrate_and_assert
SOURCE_FORM_DATA: dict[str, Any] = {
"datasource": "1__table",
"adhoc_filters": [],
"bottom_margin": 20,
"color_scheme": "default",
@@ -29,7 +30,7 @@ SOURCE_FORM_DATA: dict[str, Any] = {
"max_bubble_size": 50,
"series": ["region"],
"show_legend": True,
"size": 75,
"size": {"label": "sales", "expressionType": "SQL", "sqlExpression": "max(sales)"},
"viz_type": "bubble",
"x": "year",
"x_axis_format": "SMART_DATE",
@@ -46,6 +47,7 @@ SOURCE_FORM_DATA: dict[str, Any] = {
}
TARGET_FORM_DATA: dict[str, Any] = {
"datasource": "1__table",
"adhoc_filters": [],
"color_scheme": "default",
"entity": "count",
@@ -56,7 +58,7 @@ TARGET_FORM_DATA: dict[str, Any] = {
"row_limit": 100,
"series": ["region"],
"show_legend": True,
"size": 75,
"size": {"label": "sales", "expressionType": "SQL", "sqlExpression": "max(sales)"},
"truncateYAxis": True,
"viz_type": "bubble_v2",
"x": "year",

View File

@@ -20,6 +20,7 @@ from superset.migrations.shared.migrate_viz import MigratePivotTable
from tests.unit_tests.migrations.viz.utils import migrate_and_assert
SOURCE_FORM_DATA: dict[str, Any] = {
"datasource": "1__table",
"any_other_key": "untouched",
"columns": ["state"],
"combine_metric": True,
@@ -33,6 +34,7 @@ SOURCE_FORM_DATA: dict[str, Any] = {
}
TARGET_FORM_DATA: dict[str, Any] = {
"datasource": "1__table",
"any_other_key": "untouched",
"aggregateFunction": "Sum",
"colTotals": True,

View File

@@ -20,12 +20,14 @@ from superset.migrations.shared.migrate_viz import MigratePivotTable
from tests.unit_tests.migrations.viz.utils import migrate_and_assert
SOURCE_FORM_DATA: dict[str, Any] = {
"datasource": "1__table",
"granularity_sqla": "ds",
"time_range": "2024-04-24T00:00:00 : 2025-10-18T00:00:00",
"viz_type": "pivot_table",
}
TARGET_FORM_DATA: dict[str, Any] = {
"datasource": "1__table",
"form_data_bak": SOURCE_FORM_DATA,
"granularity_sqla": "ds",
"rowOrder": "value_z_to_a",

View File

@@ -20,6 +20,7 @@ from superset.migrations.shared.migrate_viz import MigrateViz
from superset.utils import json
TIMESERIES_SOURCE_FORM_DATA: dict[str, Any] = {
"datasource": "1__table",
"bottom_margin": 20,
"comparison_type": "absolute",
"contribution": True,
@@ -42,6 +43,7 @@ TIMESERIES_SOURCE_FORM_DATA: dict[str, Any] = {
}
TIMESERIES_TARGET_FORM_DATA: dict[str, Any] = {
"datasource": "1__table",
"comparison_type": "difference",
"contributionMode": "row",
"logAxis": True,
@@ -75,7 +77,7 @@ def migrate_and_assert(
viz_type=cls.source_viz_type,
datasource_type="table",
params=dumped_form_data,
query_context=f'{{"form_data": {dumped_form_data}}}',
query_context=f'{{"form_data": {dumped_form_data}, "queries": []}}',
)
# upgrade
@@ -83,6 +85,7 @@ def migrate_and_assert(
# verify form_data
new_form_data = json.loads(slc.params)
new_form_data.pop("queries_bak", None)
assert new_form_data == target
assert new_form_data["form_data_bak"] == source