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

Skip to content

Conversation

@mdrazak2001
Copy link
Contributor

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

  • Explanation of why no additional tests are needed
  • 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.

@sfc-gh-lwilby
Copy link
Collaborator

Thank you for working on this! Can you add some tests?

@sfc-gh-lwilby sfc-gh-lwilby self-assigned this Mar 9, 2025
@sfc-gh-lwilby sfc-gh-lwilby requested a review from Copilot March 10, 2025 16:10
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.

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:
Copy link
Collaborator

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.

@sfc-gh-lwilby sfc-gh-lwilby 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 Mar 10, 2025
@sfc-gh-lwilby sfc-gh-lwilby merged commit 3553038 into streamlit:develop Mar 12, 2025
32 checks passed
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.

Inconsistent item assignment exception for st.secrets

2 participants