Skip to content

[chore] Wire up check_widget_policies correctly in dynamic containers#14143

Merged
sfc-gh-lwilby merged 3 commits intodevelopfrom
fix/dynamic-containers-form-callback-check
Feb 27, 2026
Merged

[chore] Wire up check_widget_policies correctly in dynamic containers#14143
sfc-gh-lwilby merged 3 commits intodevelopfrom
fix/dynamic-containers-form-callback-check

Conversation

@sfc-gh-lwilby
Copy link
Copy Markdown
Collaborator

@sfc-gh-lwilby sfc-gh-lwilby commented Feb 26, 2026

Describe your changes

The partial change that landed with callable on_change support used callable(on_change) inline in the check_widget_policies call for all three dynamic containers, but without the is_callback intermediate variable or cast. This aligns all three with the established pattern from vega_charts.py:

  • Extracts is_callback = callable(on_change) as a named variable for clarity
  • Passes on_change=cast("WidgetCallback", on_change) if is_callback else None for type correctness
  • enable_check_callback_rules=is_callback (functionally equivalent, but consistent with the pattern)

Screenshot or video (only for visual changes)

N/A

GitHub Issue Link (if applicable)

Surfaced in review of #13910.

Testing Plan

  • Python unit tests — added 6 regression tests to lib/tests/streamlit/elements/layouts_test.py, covering all three containers:
    • test_callable_on_change_inside_form_raises — verifies a callable on_change inside st.form raises StreamlitInvalidFormCallbackError (expander, tabs, popover)
    • test_on_change_rerun_inside_form_does_not_raise — verifies on_change="rerun" inside st.form is still allowed (expander, tabs, popover)

Contribution License Agreement

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

sfc-gh-lwilby and others added 2 commits February 26, 2026 19:21
@sfc-gh-lwilby sfc-gh-lwilby added change:chore PR contains maintenance or housekeeping change impact:users PR changes affect end users labels Feb 26, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 26, 2026

✅ PR preview is ready!

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

@snyk-io
Copy link
Copy Markdown
Contributor

snyk-io bot commented Feb 26, 2026

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

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

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

Made-with: Cursor

Co-authored-by: lawilby <[email protected]>
@sfc-gh-lwilby sfc-gh-lwilby marked this pull request as ready for review February 27, 2026 15:11
Copilot AI review requested due to automatic review settings February 27, 2026 15:11
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 resolves a deferred follow-up item from the dynamic container callback PRs by correctly wiring up check_widget_policies in st.tabs, st.expander, and st.popover. Previously, these functions called check_widget_policies with hardcoded on_change=None and enable_check_callback_rules=False, preventing the proper validation of callback usage inside forms.

Changes:

  • Updated st.tabs, st.expander, and st.popover to follow the established pattern from chart elements (vega_charts.py, plotly_chart.py) for handling callable vs non-callable on_change parameters
  • Added comprehensive test coverage to verify that callable on_change inside st.form raises StreamlitInvalidFormCallbackError while on_change="rerun" continues to work

Reviewed changes

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

File Description
lib/streamlit/elements/layouts.py Updated tabs, expander, and popover functions to evaluate is_callback = callable(on_change) and pass it to enable_check_callback_rules in check_widget_policies, ensuring proper form callback validation
lib/tests/streamlit/elements/layouts_test.py Added 6 regression tests (2 per container type) verifying that callable on_change inside forms raises errors while on_change="rerun" does not

Copy link
Copy Markdown
Collaborator

@sfc-gh-bnisco sfc-gh-bnisco left a comment

Choose a reason for hiding this comment

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

The code LGTM, but it seems like the PR description is referring to TODOs and other items that don't seem to be reflected in the actual code changes.

@sfc-gh-lwilby
Copy link
Copy Markdown
Collaborator Author

The code LGTM, but it seems like the PR description is referring to TODOs and other items that don't seem to be reflected in the actual code changes.

Thanks for pointing this out, there were TODO comments but it seems they were removed in develop already and the PR description was wrong.

@sfc-gh-lwilby sfc-gh-lwilby merged commit cdf437f into develop Feb 27, 2026
46 checks passed
@sfc-gh-lwilby sfc-gh-lwilby deleted the fix/dynamic-containers-form-callback-check branch February 27, 2026 19:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:chore PR contains maintenance or housekeeping change impact:users PR changes affect end users

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants