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: Typo when setting the state for the pickle deserializer. #1479

Merged
merged 3 commits into from
Feb 21, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion google/auth/_refresh_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def __getstate__(self):

def __setstate__(self, state):
"""Pickle helper that deserializes the _lock attribute."""
state["_key"] = threading.Lock()
state["_lock"] = threading.Lock()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a test we could add?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK - Going to wait to hear back on #1478 before doing more

self.__dict__.update(state)


Expand Down
Binary file modified system_tests/secrets.tar.enc
Binary file not shown.
3 changes: 3 additions & 0 deletions tests/test__refresh_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,10 @@ def test_refresh_dead_worker():

def test_pickle():
w = _refresh_worker.RefreshThreadManager()
# For some reason isinstance cannot interpret threading.Lock as a type.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason is that threading.Lock is a function, returning instances of _thread.lock (internal class)

assert w._lock is not None

pickled_manager = pickle.dumps(w)
manager = pickle.loads(pickled_manager)
assert isinstance(manager, _refresh_worker.RefreshThreadManager)
assert manager._lock is not None