Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Guard delete statements. Add default fallback for _use_non_blocking_refresh. #1445

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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