-
Notifications
You must be signed in to change notification settings - Fork 4k
Add session-scoped connection support. #13506
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Add class-level `scope` method to `BaseConnection`. Use it when caching instances created by `st.connection`. Add instance-level `close` method to `BaseConnection`. Register it as the `on_release` hook when caching instances created by `st.connection`.
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
✅ PR preview is ready!
|
There was a problem hiding this 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 adds support for session-scoped connections by introducing two new methods to BaseConnection: a scope() class method to define connection scope ("global" or "session") and a close() instance method for cleanup when connections are evicted from the cache.
Key Changes
BaseConnectiongainsscope()class method (returns "global" by default) andclose()instance method (no-op by default)connection_factoryvalidates the scope, passes it tocache_resource, and registersclose()as theon_releasehook- Three new unit tests verify scope validation, scope propagation to cache, and close callback registration
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| lib/streamlit/connections/base_connection.py | Adds scope() class method and close() instance method to BaseConnection |
| lib/streamlit/runtime/connection_factory.py | Validates connection scope, passes scope and on_release hook to cache_resource, updates docstring |
| lib/tests/streamlit/runtime/connection_factory_test.py | Adds tests for scope validation, scope parameter passing, and close callback |
Add init call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ Bugbot reviewed your changes and found no bugs!
SummaryThis PR adds session-scoped connection support to Streamlit's
Code QualityThe code follows Streamlit's established patterns and conventions well:
Design Note: The spec document shows Test CoverageThe test coverage in
The tests appropriately:
E2E Tests: No e2e tests were added, which is appropriate. This PR adds infrastructure for future features (session-scoped connections) and the actual functionality is a pass-through to existing Backwards CompatibilityExcellent backward compatibility:
Security & RiskLow risk assessment:
Minor consideration: The RecommendationsThe PR is well-implemented and ready for merge. A few minor optional improvements:
VerdictAPPROVED: This PR adds well-designed, backwards-compatible infrastructure for session-scoped connections with comprehensive unit test coverage. The implementation follows Streamlit conventions, aligns with the approved product spec, and introduces no regressions to existing functionality. This is an automated AI review. Please verify the feedback and use your judgment. |
lukasmasuch
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
Describe your changes
Add class-level
scopemethod toBaseConnection. Use it when caching instances created byst.connection.Add instance-level
closemethod toBaseConnection. Register it as theon_releasehook when caching instances created byst.connection.This is part of the session-scoped connections plan, and will be used to create a Snowflake RCR connection.
Testing Plan
See unit 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.