Skip to content

Fix thread safety of lazy graph object properties - #5691

Open
hb1915 wants to merge 1 commit into
plotly:mainfrom
hb1915:fix-template-thread-safety
Open

Fix thread safety of lazy graph object properties#5691
hb1915 wants to merge 1 commit into
plotly:mainfrom
hb1915:fix-template-thread-safety

Conversation

@hb1915

@hb1915 hb1915 commented Aug 4, 2026

Copy link
Copy Markdown

Link to issue

Closes #3441

Description of change

Make lazy initialization of compound graph-object properties safe for concurrent first reads. Concurrent readers now converge on the first child or child list published to the cache, preventing a later initializer from orphaning objects already returned to another thread.

Demo

Not applicable; this fixes an intermittent server-side exception without changing rendered figures.

Testing strategy

Added a deterministic two-thread regression test for both compound and compound-array properties. The test forces the failing interleaving: it fails on unpatched main with distinct compound children and ValueError("Invalid value") for the compound array, then passes with this change.

Validation performed:

  • python -m pytest tests/test_core -q — 456 passed, 1 skipped
  • Ruff 0.11.12 check and format check on the changed Python files
  • Five end-to-end cold-template reproduction runs — 0 of 11 templates raced in every run

Additional information (optional)

The cache still permits duplicate construction during a concurrent cold read, but dict.setdefault makes publication single-winner so all readers receive objects that remain attached to their parent. This avoids adding a lock to every graph object and its associated memory, re-entrancy, deepcopy, and pickling considerations.

Guidelines

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ValueError(“Invalid value”) in basedatatypes.py

1 participant