You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by mi...@apache.org on 2025/03/17 15:01:43 UTC
(superset) 05/11: fix(migrations): Handle comparator None in old time comparison migration (#32538)
This is an automated email from the ASF dual-hosted git repository.
michaelsmolina pushed a commit to branch 5.0
in repository https://gitbox.apache.org/repos/asf/superset.git
commit d493c9d3cac0746d3c7a9f9c8287f3dd854890c4
Author: Antonio Rivero <38...@users.noreply.github.com>
AuthorDate: Fri Mar 7 16:30:24 2025 +0100
fix(migrations): Handle comparator None in old time comparison migration (#32538)
(cherry picked from commit 20e5df501e03a30c0aac2da8f0cd20a6312648f2)
---
...9123a_update_charts_with_old_time_comparison.py | 2 +-
...update_charts_with_old_time_comparison__test.py | 28 ++++++++++++++++++++++
2 files changed, 29 insertions(+), 1 deletion(-)
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 b6f975dd02..8c0a864d4f 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 a9f343b950..1ec0acca2e 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