diff --git a/google/oauth2/credentials.py b/google/oauth2/credentials.py index 4ad52db90..41f4a05bb 100644 --- a/google/oauth2/credentials.py +++ b/google/oauth2/credentials.py @@ -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): @@ -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): diff --git a/system_tests/secrets.tar.enc b/system_tests/secrets.tar.enc index 493b2222e..c5b080e8b 100644 Binary files a/system_tests/secrets.tar.enc and b/system_tests/secrets.tar.enc differ diff --git a/tests/oauth2/test_credentials.py b/tests/oauth2/test_credentials.py index 78711299e..7516fe22e 100644 --- a/tests/oauth2/test_credentials.py +++ b/tests/oauth2/test_credentials.py @@ -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))