Skip to content

Circular Import Dependency in Plotly Templates #5281

Open
@chorsington

Description

@chorsington

The issue is that plotly's template system has a circular import dependency:

  1. plotly.graph_objs.__init__.py imports all trace types including Heatmapgl
  2. During this import process, it also loads template data
  3. layout/template/data/_heatmapgl.py tries to import Heatmapgl from plotly.graph_objs
  4. But plotly.graph_objs is still in the process of being imported!

This occurred when attempting to use plotly and plotly-resampler and a heatmap.

Reproduction of Error

Minimal reproduction code:

import plotly.graph_objs as go
go.Heatmapgl()  # ✅ Success

# But this fails:
from plotly_resampler import FigureResampler
fig = FigureResampler(go.Figure())  # ❌ Circular import

Versions affected:

plotly==5.24.1
plotly-resampler==0.10.0

Work around

This can be worked around by forcing import order:

import plotly.graph_objs  # Force full initialization first
from plotly_resampler import FigureResampler  # Then import resampler

Metadata

Metadata

Assignees

Labels

P1needed for current cyclebugsomething broken

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions