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/06/09 11:56:50 UTC

(superset) 02/02: fix: Migrate charts with empty query_context (#33710)

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 e83ac1d6962ba84bf65ab1e231d29ba24cc20585
Author: Luiz Otavio <45...@users.noreply.github.com>
AuthorDate: Mon Jun 9 08:32:12 2025 -0300

    fix: Migrate charts with empty query_context (#33710)
    
    (cherry picked from commit 08655a7559718e10049fa16f83f40146402405fa)
---
 superset/migrations/shared/migrate_viz/base.py | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/superset/migrations/shared/migrate_viz/base.py b/superset/migrations/shared/migrate_viz/base.py
index 929039c0f6..e2a09731a1 100644
--- a/superset/migrations/shared/migrate_viz/base.py
+++ b/superset/migrations/shared/migrate_viz/base.py
@@ -4,7 +4,7 @@
 # regarding copyright ownership.  The ASF licenses this file
 # to you under the Apache License, Version 2.0 (the
 # "License"); you may not use this file except in compliance
-# with the License.  You may obtain a copy of the License at
+# with the License. You may obtain a copy of the License at
 #
 #   http://www.apache.org/licenses/LICENSE-2.0
 #
@@ -157,9 +157,10 @@ class MigrateViz:
             # because a source viz can be mapped to different target viz types
             slc.viz_type = clz.target_viz_type
 
-            backup = {FORM_DATA_BAK_FIELD_NAME: form_data_bak}
+            backup: Any | dict[str, Any] = {FORM_DATA_BAK_FIELD_NAME: form_data_bak}
 
             query_context = try_load_json(slc.query_context)
+            queries_bak = None
 
             if query_context:
                 if "form_data" in query_context:
@@ -169,10 +170,11 @@ class MigrateViz:
 
                 queries = clz._build_query()["queries"]
                 query_context["queries"] = queries
+            else:
+                query_context = clz._build_query()
 
-                slc.query_context = json.dumps(query_context)
-                backup[QUERIES_BAK_FIELD_NAME] = queries_bak
-
+            slc.query_context = json.dumps(query_context)
+            backup[QUERIES_BAK_FIELD_NAME] = queries_bak
             slc.params = json.dumps({**clz.data, **backup})
 
         except Exception as e:
@@ -189,11 +191,14 @@ class MigrateViz:
                 slc.viz_type = form_data_bak.get("viz_type")
                 query_context = try_load_json(slc.query_context)
                 queries_bak = form_data.get(QUERIES_BAK_FIELD_NAME, {})
-                query_context["queries"] = queries_bak
-                if "form_data" in query_context:
-                    query_context["form_data"] = form_data_bak
+                if queries_bak:
+                    query_context["queries"] = queries_bak
+                    if "form_data" in query_context:
+                        query_context["form_data"] = form_data_bak
+                        slc.query_context = json.dumps(query_context)
+                else:
+                    slc.query_context = None
 
-                slc.query_context = json.dumps(query_context)
         except Exception as e:
             logger.warning(f"Failed to downgrade slice {slc.id}: {e}")