diff --git a/superset/migrations/versions/2024-05-10_18-02_f84fde59123a_update_charts_with_old_time_comparison.py b/superset/migrations/versions/2024-05-10_18-02_f84fde59123a_update_charts_with_old_time_comparison.py index b6f975dd02c..8c0a864d4f1 100644 --- a/superset/migrations/versions/2024-05-10_18-02_f84fde59123a_update_charts_with_old_time_comparison.py +++ b/superset/migrations/versions/2024-05-10_18-02_f84fde59123a_update_charts_with_old_time_comparison.py @@ -85,7 +85,7 @@ def upgrade_comparison_params(slice_params: dict[str, Any]) -> dict[str, Any]: # Adjust adhoc_custom if "adhoc_custom" in params and params["adhoc_custom"]: adhoc = params["adhoc_custom"][0] # As there's always only one element - if adhoc["comparator"] != "No filter": + if adhoc["comparator"] and adhoc["comparator"] != "No filter": # Set start_date_offset in params, not in adhoc start_date_offset, _ = get_since_until(adhoc["comparator"]) params["start_date_offset"] = start_date_offset.strftime("%Y-%m-%d") diff --git a/tests/integration_tests/migrations/f84fde59123a_update_charts_with_old_time_comparison__test.py b/tests/integration_tests/migrations/f84fde59123a_update_charts_with_old_time_comparison__test.py index a9f343b9509..1ec0acca2ec 100644 --- a/tests/integration_tests/migrations/f84fde59123a_update_charts_with_old_time_comparison__test.py +++ b/tests/integration_tests/migrations/f84fde59123a_update_charts_with_old_time_comparison__test.py @@ -170,6 +170,23 @@ params_v2_other_than_custom_false: dict[str, Any] = { "time_compare": [], } +params_v1_with_custom_and_no_comparator: dict[str, Any] = { + **params_v1_with_custom, + "adhoc_custom": [ + { + "expressionType": "SIMPLE", + "subject": "ds", + "operator": "TEMPORAL_RANGE", + "comparator": None, + "clause": "WHERE", + "sqlExpression": None, + "isExtra": False, + "isNew": False, + "datasourceWarning": False, + } + ], +} + def test_upgrade_chart_params_with_custom(): """ @@ -241,3 +258,14 @@ def test_upgrade_chart_params_empty(): assert downgrade_comparison_params(None) == {} assert downgrade_comparison_params({}) == {} assert downgrade_comparison_params("") == {} + + +def test_upgrade_chart_params_with_custom_no_comparator(): + """ + ensure that the new time comparison params are added but no start_date_offset + """ + original_params = deepcopy(params_v1_with_custom_and_no_comparator) + expected_after_upgrade = deepcopy(params_v2_with_custom) + expected_after_upgrade.pop("start_date_offset") + upgraded_params = upgrade_comparison_params(original_params) + assert upgraded_params == expected_after_upgrade