EnxDev commented on code in PR #45301:
URL: https://github.com/apache/superset/pull/45301#discussion_r4276221291


##########
superset/commands/dashboard/importers/v1/utils.py:
##########
@@ -110,8 +112,9 @@ def update_id_refs(  # pylint: disable=too-many-locals  # 
noqa: C901
 
     if "expanded_slices" in metadata:
         metadata["expanded_slices"] = {
-            str(id_map[int(old_id)]): value
+            str(new_id): value
             for old_id, value in metadata["expanded_slices"].items()
+            if (new_id := _remap_legacy_chart_id(old_id, id_map)) is not None
         }
 
     if "default_filters" in metadata:

Review Comment:
   Not blocking, but a non-numeric key like `{"abc": ...}` still throws 
`ValueError` here and in `filter_scopes` above, since both do a bare 
`int(old_id)` before the membership check. That's the same failure as row 3 in 
your table.
   
   Since the helper exists now, would you be up for routing these two through 
`_remap_legacy_chart_id` too? Fine to leave for a follow-up if you'd rather 
keep this one narrow.



##########
superset/commands/dashboard/importers/v1/utils.py:
##########
@@ -183,6 +186,23 @@ def update_id_refs(  # pylint: disable=too-many-locals  # 
noqa: C901
     return fixed
 
 
+def _remap_legacy_chart_id(old_id: Any, id_map: dict[int, int]) -> int | None:
+    """Map one legacy integer chart ID to its new ID, or ``None``.
+
+    The integer-keyed metadata fields can hold a string rather than an int, and
+    can name a chart that is not in the bundle: nothing prunes them when a
+    chart is deleted or leaves a dashboard, and a chart in the layout is
+    skipped at import when its dataset is unresolvable. Returning ``None`` lets
+    the caller drop an unresolvable reference rather than fail the whole
+    import. The exporter coerces the same fields the same way; see
+    ``superset.commands.dashboard.export._stabilize_chart_ids``.
+    """
+    try:
+        return id_map.get(int(old_id))

Review Comment:
   Nothing in the new tests reaches this branch, which lines up with the 2 
uncovered lines codecov reports. The description says there's one test per 
table row, but the `{"abc": true}` row isn't covered.
   
   Adding an `"abc": True` entry to the input in 
`test_update_id_refs_expanded_slices_missing` would cover it.



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