-
Notifications
You must be signed in to change notification settings - Fork 4k
[Fix]: inconsistent error messages for st.secrets attribute assignment #10698
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
[Fix]: inconsistent error messages for st.secrets attribute assignment #10698
Conversation
|
Thank you for working on this! Can you add some tests? |
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.
PR Overview
This PR fixes inconsistent error messages when attempting to assign a value to st.secrets using attribute assignment by ensuring both item and attribute assignments raise a TypeError with the same message.
- Added a unit test to verify that attribute assignment to st.secrets raises the expected TypeError.
- Updated the setattr method to allow setting of internal attributes while still rejecting external attribute assignments.
Reviewed Changes
| File | Description |
|---|---|
| lib/tests/streamlit/runtime/secrets_test.py | Added test case to validate attribute assignment error message |
| lib/streamlit/runtime/secrets.py | Updated setattr to enforce consistent error messaging for assignments |
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
Comments suppressed due to low confidence (1)
lib/streamlit/runtime/secrets.py:495
- [nitpick] Consider adding an inline comment to explain the rationale behind the allowed keys list (internal attributes) to improve code clarity and maintainability.
def __setattr__(self, key: str, value: Any) -> None:
| except KeyError: | ||
| raise KeyError(_missing_key_error_message(key)) | ||
|
|
||
| def __setattr__(self, key: str, value: Any) -> None: |
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.
I see there are some other tests that utilize this path, but I think it would be good to also include an explicit test for this path as well.
Describe your changes
Make the error message consistent between item assignment (st.secrets["foo"] = "bar") and attribute assignment (st.secrets.foo = "bar"). Both now raise a TypeError with a clear message indicating that Secrets does not support assignment.
GitHub Issue Link (if applicable)
fixes #10107
Testing Plan
Contribution License Agreement
By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.