Rolling back Plotly after a figure schema upgrade: what breaks when figure['version'] no longer matches
0 reputation · 18 Apr 2020, 02:52 UTC
0 reputation · 18 Apr 2020, 02:52 UTC
Plotly has stored a figure['version'] field in serialized figures since v5.3, and loading a figure written by a newer release can trigger compatibility checks or silently drop unknown trace attributes. I am planning an upgrade from Plotly 5.x to a newer 5.x/6.x line and need a rollback strategy for figures already saved with plotly.io.write_json.
The constraint is that some saved figures may contain trace types or layout properties introduced only in the newer schema. On downgrade, plotly.io.from_json appears to tolerate compatible fields, but removed or unrecognized attributes risk being lost without an explicit error, and layout.template references may fall back to defaults.
My questions:
fig['version'] against the installed Plotly version sufficient to guarantee a figure survives a downgrade, or are there schema changes that pass this check but still lose data?to_image with staticPlot the recommended safety net when interactivity loss on rollback is acceptable?fig['version'] no longer matches the installed Plotly release?Plotly stores a fig['version'] key that records the figure schema version used when the figure was serialized. When plotly.io.from_json loads a figure whose version is newer than the running library, the loader performs a compatibility check:
UserWarning about the version mismatch.scattergl, sunburst) are converted to the closest known type or removed entirely.These changes occur even if the fig['version'] value is numerically equal to the installed Plotly version. The version field only guarantees that the figure was written by a *release* of Plotly, not that the *schema* is identical across releases. Minor releases often introduce new properties that do not increment the major version number but still break older clients.
No. Checking fig['version'] against the installed Plotly version only tells you that the figure was written by a *compatible* release. It does not account for schema changes that add new keys or trace types. The safest approach is to load the figure with the older library and then compare the keys before and after to detect any silent drops. If you need the data to survive, you must either keep the newer library or explicitly strip unsupported keys before serialization.
Plotly does not ship a dedicated downgrade helper. The recommended workflow when you must revert to an older library is:
pip install plotly==5.13.0).plotly.io.from_json and let the library discard unknown keys.plotly.io.to_json (or write_json) so that the file now matches the older schema.Alternatively, manually prune unsupported keys before serialization if you need to preserve as much information as possible.
If interactivity is not required after rollback, fig.to_image(static_plot=True) (or to_image(..., static_plot=True)) produces a PNG/SVG that reflects the visual state of the figure as rendered by the newer library. This approach:
Use this method when you only need a static representation for documentation or archival purposes.
# 1. Create a figure with a trace type only available in Plotly 6.x
import plotly.graph_objects as go
fig = go.Figure(go.Scattergl(x=[1,2,3], y=[4,5,6]))
fig.write_json('new_figure.json')
# 2. Downgrade to Plotly 5.x
# pip install plotly==5.13.0
# 3. Load and inspect
import plotly.io as pio
fig_old = pio.from_json('new_figure.json')
print(fig_old.data) # Trace type may be missing or converted
print(fig_old.layout) # Template fallback may occur
After the round‑trip, compare fig_old.to_dict().keys() with the original to confirm which keys were dropped.
fig['version'] for safe downgrade.Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.