Skip to content
This repository was archived by the owner on Feb 23, 2026. It is now read-only.

fix: save empty IAM policy bindings - #155

Merged
busunkim96 merged 2 commits into
masterfrom
fix-154
Mar 23, 2021
Merged

fix: save empty IAM policy bindings#155
busunkim96 merged 2 commits into
masterfrom
fix-154

Conversation

@busunkim96

@busunkim96busunkim96 commented Mar 22, 2021

Copy link
Copy Markdown
Contributor

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 teamMarch 22, 2021 21:52
@google-clagoogle-claBot 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
Copy Markdown
ContributorAuthor

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 merged commit 536c2ca into masterMar 23, 2021
@busunkim96
busunkim96 deleted the fix-154 branch March 23, 2021 19:16
gcf-merge-on-greenBot 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 freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla: yesThis 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

@busunkim96@parthea