Skip to content

Use key as main identity for st.number_input#12437

Merged
lukasmasuch merged 7 commits intodevelopfrom
stable-key-identity-for-number-input
Sep 5, 2025
Merged

Use key as main identity for st.number_input#12437
lukasmasuch merged 7 commits intodevelopfrom
stable-key-identity-for-number-input

Conversation

@lukasmasuch
Copy link
Copy Markdown
Collaborator

@lukasmasuch lukasmasuch commented Sep 5, 2025

Describe your changes

If a custom key is passed to any of the st.number_input widgets it will be used as the main identity. This allows for dynamically changing other parameters in between reruns without causing the widgets to be recreated in the frontend.

GitHub Issue Link (if applicable)

Testing Plan

  • Added unit & e2e tests.

Contribution License Agreement

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

@snyk-io
Copy link
Copy Markdown
Contributor

snyk-io bot commented Sep 5, 2025

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

security/snyk check is complete. No issues have been found. (View Details)

license/snyk check is complete. No issues have been found. (View Details)

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Sep 5, 2025

✅ PR preview is ready!

Name Link
📦 Wheel file https://core-previews.s3-us-west-2.amazonaws.com/pr-12437/streamlit-1.49.1-py3-none-any.whl
🕹️ Preview app pr-12437.streamlit.app (☁️ Deploy here if not accessible)

@lukasmasuch lukasmasuch added security-assessment-completed change:breaking PR contains breaking change that affects backwards compatibility change:feature PR contains new feature or enhancement implementation impact:users PR changes affect end users labels Sep 5, 2025
@lukasmasuch lukasmasuch requested a review from Copilot September 5, 2025 01:03
Copy link
Copy Markdown
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 enables st.number_input widgets to use a custom key as the main identity when provided, allowing dynamic parameter changes between reruns without recreating the widget in the frontend. This addresses issue #11277 by maintaining widget state when non-core parameters are modified.

  • Modified the key_as_main_identity parameter to whitelist specific parameters (min_value, max_value, step) that still affect widget identity
  • Added comprehensive unit tests to verify stable widget IDs with keys and parameter changes
  • Implemented end-to-end tests demonstrating dynamic property updates while preserving widget state

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
lib/streamlit/elements/widgets/number_input.py Updated key_as_main_identity to use a whitelist of core parameters instead of False
lib/tests/streamlit/elements/number_input_test.py Added unit tests for stable ID behavior and whitelisted parameter validation
e2e_playwright/st_number_input.py Added test script with dynamic number input demonstrating property updates
e2e_playwright/st_number_input_test.py Added E2E test validating dynamic property changes preserve widget state

@lukasmasuch lukasmasuch marked this pull request as ready for review September 5, 2025 09:17
expect_markdown(app, "Initial number input value: 7")

# Click the toggle to update the number input props
from e2e_playwright.shared.app_utils import click_toggle
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.

Move the import statement from e2e_playwright.shared.app_utils import click_toggle to the module level at the top of the file. According to the Python Guide, imports should be organized at the top of the file rather than inside functions to follow proper Python import organization.

Spotted by Diamond (based on custom rule: Python Guide)

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

@lukasmasuch lukasmasuch merged commit 3c5a885 into develop Sep 5, 2025
37 checks passed
@lukasmasuch lukasmasuch deleted the stable-key-identity-for-number-input branch September 5, 2025 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:breaking PR contains breaking change that affects backwards compatibility change:feature PR contains new feature or enhancement implementation impact:users PR changes affect end users

Projects

None yet

3 participants