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


##########
superset/commands/dashboard/export.py:
##########
@@ -105,6 +106,172 @@ def append_charts(position: dict[str, Any], charts: 
set[Slice]) -> dict[str, Any
     return position
 
 
+# Bound the derived id to the largest positive signed 32-bit integer
+# (2**31 - 1) so it stays within the range a database auto-increment primary
+# key would occupy and never collides with the sign bit. The concrete value is
+# irrelevant — only its stability across environments matters.
+_STABLE_CHART_ID_MODULO = 2_147_483_647
+
+
+def stable_chart_id(chart_uuid: str) -> int:
+    """Derive a deterministic, environment-independent integer from a chart 
UUID.
+
+    The dashboard export format historically embedded ``meta.chartId`` — the
+    source environment's auto-increment primary key — inside every ``CHART-*``
+    position node (issue #32972). That integer differs between environments, so
+    re-exporting an imported dashboard produced a different bundle for the same
+    logical content. Deriving the id from the (stable) UUID instead makes the
+    export reproducible while still giving the importer an integer it can use 
to
+    rewire the legacy, integer-keyed metadata references back to local IDs.
+    """
+    return (uuid_module.UUID(chart_uuid).int % _STABLE_CHART_ID_MODULO) + 1

Review Comment:
   Good catch — the collision is wildly improbable but not impossible. Made it 
collision-safe: charts are processed in UUID order and a duplicate derived id 
probes forward deterministically, so the metadata remaps can never silently 
merge. Added a test that forces a collision via a stubbed `stable_chart_id`.



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