fix: do not attempt to mutate secret data in grant/revoke during tests#2614
Open
tonyandrewmeyer wants to merge 1 commit into
Open
fix: do not attempt to mutate secret data in grant/revoke during tests#2614tonyandrewmeyer wants to merge 1 commit into
tonyandrewmeyer wants to merge 1 commit into
Conversation
Since ops 3.8.0, Secret.remote_grants values are frozensets, but secret_grant and secret_revoke still called .add() and .remove() on them, raising AttributeError when a charm revoked a pre-existing grant. Replace the in-place mutations with reassignment using set operators. Fixes canonical#2613 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Audit of the rest of
mocking.pyfor other places affected by the state-type refactor in #2331:open_port/close_port,secret_add/secret_remove: already copy the frozenset to a mutable set, mutate, then reassign via the_update_*helpers._update_state_check_infos: reassignscheck_infosviaobject.__setattr__with a freshfrozenset.secret_set: goes throughSecret._update_metadata, which usesobject.__setattr__.local_app_data, etc.) and Container mappings (layers,service_statuses,mounts): annotations were tightened toMapping, but the state classes still construct plaindicts in__init__, so in-place mutation is still valid at runtime.remote_grantswas the only field that actually flipped fromsettofrozensetat runtime, andsecret_grant/secret_revokewere the only callers assuming mutability.Pyright would have caught this — running it directly on the pre-fix code flags
Cannot access attribute "add"/"remove" for class "frozenset[str]"— buttool.pyright.includeinpyproject.tomlusestesting/src/*.py, which does not matchtesting/src/scenario/*.py, so the scenario source is silently unchecked. I'll fix that in a separate PR.Fixes #2613