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

GithubObjects are no longer serializable with pickle #2436

Closed
josh-fell opened this issue Feb 23, 2023 · 2 comments · Fixed by #2446
Closed

GithubObjects are no longer serializable with pickle #2436

josh-fell opened this issue Feb 23, 2023 · 2 comments · Fixed by #2446

Comments

@josh-fell
Copy link

To support data exchange, being able to serialize non-JSON-serializable GithubObjects has been easily achieved in past with pickle. However, starting with v1.58, GithubObjects like Repository, NamedUser, etc. are no longer serializable with with pickle,

For example,

import github
import pickle

repo = github.Github().get_repo(full_name_or_id="PyGithub/PyGithub")
pickle.dumps(repo)

raise the following exception:

Traceback (most recent call last):
  File "/Users/joshfell/code/daedalus/tempCodeRunnerFile.python", line 15, in <module>
    pickle.dumps(repo)
  File "/usr/local/Cellar/python@3.10/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10/multiprocessing/synchronize.py", line 101, in __getstate__
    context.assert_spawning(self)
  File "/usr/local/Cellar/python@3.10/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10/multiprocessing/context.py", line 373, in assert_spawning
    raise RuntimeError(
RuntimeError: RLock objects should only be shared between processes through inheritance

The underyling Requester object now has an RLock() attribute, __auth_lock, which looks to be preventing this serialization.

@EnricoMi
Copy link
Collaborator

EnricoMi commented Feb 23, 2023

Pickle allows Requester to exclude the lock from being serialized:
https://docs.python.org/3/library/pickle.html#handling-stateful-objects

And we should add tests that prove pickle support.

@josh-fell
Copy link
Author

@EnricoMi, Thanks for taking a look so quickly and the tip on the pickle workaround!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants