Skip to content

Commit

Permalink
fix: Guard delete statements. Add default fallback for _use_non_block…
Browse files Browse the repository at this point in the history
…ing_refresh. (#1445)
  • Loading branch information
clundin25 authored Dec 20, 2023
1 parent a6dc2c3 commit 776d634
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
10 changes: 6 additions & 4 deletions google/oauth2/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,11 @@ def __getstate__(self):
# unpickling certain callables (lambda, functools.partial instances)
# because they need to be importable.
# Instead, the refresh_handler setter should be used to repopulate this.
del state_dict["_refresh_handler"]
# Remove worker as it contains multiproccessing queue objects.
del state_dict["_refresh_worker"]
if "_refresh_handler" in state_dict:
del state_dict["_refresh_handler"]

if "_refresh_worker" in state_dict:
del state_dict["_refresh_worker"]
return state_dict

def __setstate__(self, d):
Expand All @@ -186,7 +188,7 @@ def __setstate__(self, d):
# The refresh_handler setter should be used to repopulate this.
self._refresh_handler = None
self._refresh_worker = None
self._use_non_blocking_refresh = d.get("_use_non_blocking_refresh")
self._use_non_blocking_refresh = d.get("_use_non_blocking_refresh", False)

@property
def refresh_token(self):
Expand Down
Binary file modified system_tests/secrets.tar.enc
Binary file not shown.
2 changes: 2 additions & 0 deletions tests/oauth2/test_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,8 @@ def test_pickle_with_missing_attribute(self):
# this mimics a pickle created with a previous class definition with
# fewer attributes
del creds.__dict__["_quota_project_id"]
del creds.__dict__["_refresh_handler"]
del creds.__dict__["_refresh_worker"]

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

Expand Down

0 comments on commit 776d634

Please sign in to comment.