Skip to content

Commit 776d634

Browse files
authored
fix: Guard delete statements. Add default fallback for _use_non_blocking_refresh. (#1445)
1 parent a6dc2c3 commit 776d634

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

google/oauth2/credentials.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,11 @@ def __getstate__(self):
160160
# unpickling certain callables (lambda, functools.partial instances)
161161
# because they need to be importable.
162162
# Instead, the refresh_handler setter should be used to repopulate this.
163-
del state_dict["_refresh_handler"]
164-
# Remove worker as it contains multiproccessing queue objects.
165-
del state_dict["_refresh_worker"]
163+
if "_refresh_handler" in state_dict:
164+
del state_dict["_refresh_handler"]
165+
166+
if "_refresh_worker" in state_dict:
167+
del state_dict["_refresh_worker"]
166168
return state_dict
167169

168170
def __setstate__(self, d):
@@ -186,7 +188,7 @@ def __setstate__(self, d):
186188
# The refresh_handler setter should be used to repopulate this.
187189
self._refresh_handler = None
188190
self._refresh_worker = None
189-
self._use_non_blocking_refresh = d.get("_use_non_blocking_refresh")
191+
self._use_non_blocking_refresh = d.get("_use_non_blocking_refresh", False)
190192

191193
@property
192194
def refresh_token(self):

system_tests/secrets.tar.enc

0 Bytes
Binary file not shown.

tests/oauth2/test_credentials.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,8 @@ def test_pickle_with_missing_attribute(self):
963963
# this mimics a pickle created with a previous class definition with
964964
# fewer attributes
965965
del creds.__dict__["_quota_project_id"]
966+
del creds.__dict__["_refresh_handler"]
967+
del creds.__dict__["_refresh_worker"]
966968

967969
unpickled = pickle.loads(pickle.dumps(creds))
968970

0 commit comments

Comments
 (0)