Skip to content

Fix thread safety of lazy graph object properties - #5691

Merged
KoolADE85 merged 2 commits into
plotly:mainfrom
hb1915:fix-template-thread-safety
Sep 17, 2026
Merged

KoolADE85 merged 2 commits into
plotly:mainfrom
hb1915:fix-template-thread-safety

Conversation

@hb1915

@hb1915 hb1915 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

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

@hb1915

hb1915 commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

Let me know if anything I can clarify @emilykl

@robertclaus
robertclaus requested review from KoolADE85 and removed request for emilykl September 15, 2026 20:11
@robertclaus robertclaus assigned KoolADE85 and unassigned emilykl Sep 15, 2026
KoolADE85
KoolADE85 previously approved these changes Sep 16, 2026

@KoolADE85 KoolADE85 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @hb1915, sorry for the review delay here. Thanks for submitting this bugfix! It works well on my end.
If you can fix the conflict in the CHANGELOG, I'll be good to merge the PR.
Cheers!

Comment thread CHANGELOG.md Outdated
AI-Authored-By: openai/gpt-6-astra
Co-authored-by: Adrian Borrmann <hello@adrianborrmann.com>
@hb1915

hb1915 commented Sep 17, 2026

Copy link
Copy Markdown
Contributor Author

should be there now - tyvm @KoolADE85 :)

@KoolADE85
KoolADE85 merged commit 01fe2b8 into plotly:main Sep 17, 2026
26 checks passed
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

3 participants