From 536c2cad814b8fa8cd346a3d7bd5f6b9889c4a6f Mon Sep 17 00:00:00 2001 From: Bu Sun Kim <8822365+busunkim96@users.noreply.github.com> Date: Tue, 23 Mar 2021 13:16:34 -0600 Subject: fix: save empty IAM policy bindings (#155) --- google/api_core/iam.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'google') diff --git a/google/api_core/iam.py b/google/api_core/iam.py index f130936..d83cbf3 100644 --- a/google/api_core/iam.py +++ b/google/api_core/iam.py @@ -136,7 +136,10 @@ class Policy(collections_abc.MutableMapping): for b in self._bindings: if b["role"] == key: return b["members"] - return set() + # binding does not yet exist, create one + new_binding = {"role": key, "members": set()} + self._bindings.append(new_binding) + return new_binding["members"] def __setitem__(self, key, value): self.__check_version__() -- cgit v1.2.3