From a4d8f36863e16a8c75aec2a75f2a185b6ca1d3c5 Mon Sep 17 00:00:00 2001 From: Beto Dealmeida Date: Tue, 26 Sep 2023 19:31:34 -0700 Subject: [PATCH] fix: chart import (#25425) --- superset/charts/commands/importers/v1/utils.py | 4 ++-- tests/unit_tests/charts/commands/importers/v1/utils_test.py | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/superset/charts/commands/importers/v1/utils.py b/superset/charts/commands/importers/v1/utils.py index d3f90f7ff4312..3ef0a2ed78b49 100644 --- a/superset/charts/commands/importers/v1/utils.py +++ b/superset/charts/commands/importers/v1/utils.py @@ -99,8 +99,8 @@ def migrate_chart(config: dict[str, Any]) -> dict[str, Any]: # also update `query_context` try: - query_context = json.loads(output.get("query_context", "{}")) - except json.decoder.JSONDecodeError: + query_context = json.loads(output.get("query_context") or "{}") + except (json.decoder.JSONDecodeError, TypeError): query_context = {} if "form_data" in query_context: query_context["form_data"] = output["params"] 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 c99ecaf6d6da7..77d31e7d776b3 100644 --- a/tests/unit_tests/charts/commands/importers/v1/utils_test.py +++ b/tests/unit_tests/charts/commands/importers/v1/utils_test.py @@ -32,6 +32,7 @@ def test_migrate_chart_area() -> None: "certified_by": None, "certification_details": None, "viz_type": "area", + "query_context": None, "params": json.dumps( { "adhoc_filters": [],