Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@sfc-gh-tteixeira
Copy link
Contributor

@sfc-gh-tteixeira sfc-gh-tteixeira commented Sep 30, 2025

Describe your changes

Today, our Altair-handling code in Python does some things that modify global variables in the altair module differently for each chart, which makes the code thead-unsafe. This leads to empty charts whenever two charts are drawn at the same time in different threads.

This PR addresses that by wrapping the thread-unsafe code into a threading.Lock, plus a couple of small refactors.

GitHub Issue Link (if applicable)

none

Testing Plan

  • Explanation of why no additional tests are needed: I'm having a hard time coming up with tests for this. Any ideas? I found that this can be reproduced 100% of the time by drawing two charts in two different threads, but I'm not sure that's actually guaranteed to be true. I worry about creating a flaky e2e test this way.
  • Unit Tests (JS and/or Python)
  • E2E Tests
  • Any manual testing needed?

Contribution License Agreement

By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.

@github-actions
Copy link
Contributor

github-actions bot commented Sep 30, 2025

✅ PR preview is ready!

Name Link
📦 Wheel file https://core-previews.s3-us-west-2.amazonaws.com/pr-12673/streamlit-1.50.0-py3-none-any.whl
📦 @streamlit/component-v2-lib Download from artifacts
🕹️ Preview app pr-12673.streamlit.app (☁️ Deploy here if not accessible)

@snyk-io
Copy link
Contributor

snyk-io bot commented Sep 30, 2025

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Licenses 0 0 0 0 0 issues
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@lukasmasuch lukasmasuch requested a review from Copilot October 13, 2025 21:25
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR makes Streamlit's Altair chart handling code thread-safe by wrapping thread-unsafe operations in a threading lock. The main issue addressed is that Altair's global variables for themes and data transformers were being modified concurrently, causing empty charts when multiple charts were rendered simultaneously in different threads.

  • Introduces a threading lock to protect Altair global state modifications
  • Refactors the data transformer function to be a standalone module-level function
  • Updates comments to reflect the new transformer function name

@kmcgrady kmcgrady added security-assessment-completed Security assessment has been completed for PR change:bugfix PR contains bug fix implementation impact:users PR changes affect end users labels Oct 13, 2025
Copy link
Collaborator

@kmcgrady kmcgrady left a comment

Choose a reason for hiding this comment

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

Things LGTM overall. I agree with testing. I remember we had some e2e tests failing likely due to this scenario, but we must have found a workaround on the tests. We do mark some as flaky so perhaps we can test drive removing it, but that seems like a separate initiative.

@sfc-gh-tteixeira sfc-gh-tteixeira enabled auto-merge (squash) October 14, 2025 13:59
@sfc-gh-tteixeira sfc-gh-tteixeira merged commit 44caa2a into develop Oct 14, 2025
38 checks passed
@sfc-gh-tteixeira sfc-gh-tteixeira deleted the vega-threading branch October 14, 2025 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:bugfix PR contains bug fix implementation impact:users PR changes affect end users security-assessment-completed Security assessment has been completed for PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants