rusackas commented on code in PR #41714:
URL: https://github.com/apache/superset/pull/41714#discussion_r3726597057


##########
superset/migrations/shared/migrate_viz/base.py:
##########
@@ -164,11 +172,22 @@ def upgrade_slice(cls, slc: Slice) -> None:
             queries_bak = None
 
             if query_context:
+                # A stored query_context is expected to carry "queries", but
+                # an atypical/malformed one (e.g. hand-edited via the API)
+                # missing it must not raise here: viz_type was already
+                # flipped above, so an uncaught exception at this point
+                # would leave the slice half-migrated (new viz_type, but
+                # stale params/query_context in the old shape). Back up the
+                # whole context in that case so downgrade can restore it
+                # verbatim instead of losing it (see FULL_CONTEXT_BAK_KEY).
+                if "queries" in query_context:

Review Comment:
   Same fix covers this one too, now validates it's a dict before touching it 
and falls back to the wholesale backup otherwise, so it can't raise 
mid-migration.



##########
superset-frontend/plugins/preset-chart-deckgl/src/Multi/Multi.tsx:
##########
@@ -409,8 +537,89 @@ const DeckMulti = (props: DeckMultiProps) => {
   const prevDeckSlices = usePrevious(props.formData.deck_slices);
   const prevVisibleLayersRedux = usePrevious(visibleDeckLayersFromRedux);
 
+  const toLayerFormData = useCallback(
+    (
+      sliceId: number,
+      result: JsonObject,
+    ): ({ slice_id: number } & JsonObject) | null => {
+      let params: JsonObject = {};
+      try {
+        params = JSON.parse(result.params || '{}');
+      } catch {
+        params = {};
+      }
+      // The saved params carry a `datasource` string, but it can be
+      // stale (e.g. example charts hardcode an id that differs from the
+      // imported dataset's real id). Prefer the chart's authoritative
+      // datasource_id/datasource_type so the layer queries the dataset
+      // it is actually bound to, the same one it uses standalone.
+      const datasource =
+        result.datasource_id != null && result.datasource_type
+          ? `${result.datasource_id}__${result.datasource_type}`
+          : params.datasource;
+      return {
+        slice_id: sliceId,
+        form_data: {
+          ...params,
+          datasource,
+          slice_id: sliceId,
+          viz_type: result.viz_type ?? params.viz_type,
+        },
+      };
+    },
+    [],
+  );
+
+  const fetchSubslicesPerChart = useCallback(
+    (sliceIds: number[]) =>
+      Promise.all<({ slice_id: number } & JsonObject) | null>(
+        sliceIds.map(sliceId =>
+          SupersetClient.get({ endpoint: `/api/v1/chart/${sliceId}` })
+            .then(({ json }) =>
+              toLayerFormData(sliceId, (json as JsonObject).result || {}),
+            )
+            .catch(() => null),
+        ),
+      ).then(slices =>
+        slices.filter(
+          (slice): slice is { slice_id: number } & JsonObject => slice !== 
null,
+        ),
+      ),
+    [toLayerFormData],
+  );
+
+  const fetchSubslices = useCallback(
+    (sliceIds: number[]) => {
+      const containerId = props.formData.slice_id;

Review Comment:
   Added a per-chart fallback for any deck_slices id missing from the bulk 
deck_layers response, so a newly added layer previews before you save.



-- 
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