michael-s-molina commented on code in PR #33037:
URL: https://github.com/apache/superset/pull/33037#discussion_r2042850161


##########
superset/migrations/shared/migrate_viz/base.py:
##########
@@ -121,34 +121,44 @@ def _migrate_temporal_filter(self, rv_data: dict[str, 
Any]) -> None:
 
     @classmethod
     def upgrade_slice(cls, slc: Slice) -> None:
-        clz = cls(slc.params)
-        form_data_bak = copy.deepcopy(clz.data)
+        try:
+            clz = cls(slc.params)
+            form_data_bak = copy.deepcopy(clz.data)
 
-        clz._pre_action()
-        clz._migrate()
-        clz._post_action()
+            clz._pre_action()
+            clz._migrate()
+            clz._post_action()
 
-        # viz_type depends on the migration and should be set after its 
execution
-        # because a source viz can be mapped to different target viz types
-        slc.viz_type = clz.target_viz_type
+            # viz_type depends on the migration and should be set after its 
execution
+            # because a source viz can be mapped to different target viz types
+            slc.viz_type = clz.target_viz_type
 
-        # only backup params
-        slc.params = json.dumps({**clz.data, FORM_DATA_BAK_FIELD_NAME: 
form_data_bak})
+            # only backup params
+            slc.params = json.dumps(
+                {**clz.data, FORM_DATA_BAK_FIELD_NAME: form_data_bak}
+            )
 
-        if "form_data" in (query_context := try_load_json(slc.query_context)):
-            query_context["form_data"] = clz.data
-            slc.query_context = json.dumps(query_context)
+            if "form_data" in (query_context := 
try_load_json(slc.query_context)):
+                query_context["form_data"] = clz.data
+                slc.query_context = json.dumps(query_context)
+        except Exception as e:
+            print(f"Failed to migrate slice {slc.id}: {e}")
 
     @classmethod
     def downgrade_slice(cls, slc: Slice) -> None:
-        form_data = try_load_json(slc.params)
-        if "viz_type" in (form_data_bak := 
form_data.get(FORM_DATA_BAK_FIELD_NAME, {})):
-            slc.params = json.dumps(form_data_bak)
-            slc.viz_type = form_data_bak.get("viz_type")
-            query_context = try_load_json(slc.query_context)
-            if "form_data" in query_context:
-                query_context["form_data"] = form_data_bak
-                slc.query_context = json.dumps(query_context)
+        try:
+            form_data = try_load_json(slc.params)
+            if "viz_type" in (
+                form_data_bak := form_data.get(FORM_DATA_BAK_FIELD_NAME, {})
+            ):
+                slc.params = json.dumps(form_data_bak)
+                slc.viz_type = form_data_bak.get("viz_type")
+                query_context = try_load_json(slc.query_context)
+                if "form_data" in query_context:
+                    query_context["form_data"] = form_data_bak
+                    slc.query_context = json.dumps(query_context)
+        except Exception as e:
+            print(f"Failed to downgrade slice {slc.id}: {e}")

Review Comment:
   👍🏼 



##########
superset/migrations/shared/migrate_viz/base.py:
##########
@@ -121,34 +121,44 @@ def _migrate_temporal_filter(self, rv_data: dict[str, 
Any]) -> None:
 
     @classmethod
     def upgrade_slice(cls, slc: Slice) -> None:
-        clz = cls(slc.params)
-        form_data_bak = copy.deepcopy(clz.data)
+        try:
+            clz = cls(slc.params)
+            form_data_bak = copy.deepcopy(clz.data)
 
-        clz._pre_action()
-        clz._migrate()
-        clz._post_action()
+            clz._pre_action()
+            clz._migrate()
+            clz._post_action()
 
-        # viz_type depends on the migration and should be set after its 
execution
-        # because a source viz can be mapped to different target viz types
-        slc.viz_type = clz.target_viz_type
+            # viz_type depends on the migration and should be set after its 
execution
+            # because a source viz can be mapped to different target viz types
+            slc.viz_type = clz.target_viz_type
 
-        # only backup params
-        slc.params = json.dumps({**clz.data, FORM_DATA_BAK_FIELD_NAME: 
form_data_bak})
+            # only backup params
+            slc.params = json.dumps(
+                {**clz.data, FORM_DATA_BAK_FIELD_NAME: form_data_bak}
+            )
 
-        if "form_data" in (query_context := try_load_json(slc.query_context)):
-            query_context["form_data"] = clz.data
-            slc.query_context = json.dumps(query_context)
+            if "form_data" in (query_context := 
try_load_json(slc.query_context)):
+                query_context["form_data"] = clz.data
+                slc.query_context = json.dumps(query_context)
+        except Exception as e:
+            print(f"Failed to migrate slice {slc.id}: {e}")

Review Comment:
   👍🏼 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to