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

Skip to content

Conversation

busunkim96
Copy link
Contributor

@busunkim96 busunkim96 commented Mar 22, 2021

Fixes #154

__getitem__ currently returns an empty set() for items not in the bindings. If someone adds to the set returned by __getitem__ the changes will not be reflected on the actual policy object.

@busunkim96 busunkim96 requested a review from a team as a code owner March 22, 2021 21:52
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Mar 22, 2021
Comment on lines +35 to +36
assert len(policy) == 0
assert dict(policy) == {}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Accessing policy.owners, policy.editors results in __getitem__ being called, which adds empty entries to the dictionary. I moved these empty dict asserts up as a result.

An alternative is to keep them in their previous location and check that the three roles with empty bindings were added

@busunkim96 busunkim96 requested review from frankyn and parthea March 22, 2021 21:56
@busunkim96 busunkim96 merged commit 536c2ca into master Mar 23, 2021
@busunkim96 busunkim96 deleted the fix-154 branch March 23, 2021 19:16
gcf-merge-on-green bot pushed a commit that referenced this pull request Mar 25, 2021
Exclude empty policy bindings (bindings with no members) in
`Policy.__iter__()` and `Policy.__len__()`

Follow up to #155
This was referenced May 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

google.api_core.iam.Policy.__getitem__ does not correctly save empty bindings
2 participants