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

ArtifactoryPath: override PurePath.__reduce__ to fix pickling #456

Merged
merged 1 commit into from
Sep 27, 2024

Conversation

OddBloke
Copy link
Contributor

pathlib.PurePath instances can be reconstructed from only self._parts, so that is all that PurePath.__reduce__ returns. This means that pickling an ArtifactoryPath objects strips out all other instance state including, crucially, self.session and the auth data it includes.

This commit overrides __reduce__ to include self.__dict__ in the returned tuple, which is restored as instance state on unpickle per https://docs.python.org/3/library/pickle.html#object.__reduce__.

`pathlib.PurePath` instances can be reconstructed from only
`self._parts`, so that is all that `PurePath.__reduce__` returns.  This
means that pickling an `ArtifactoryPath` objects strips out all other
instance state including, crucially, `self.session` and the auth data it
includes.

This commit overrides `__reduce__` to include `self.__dict__` in the
returned tuple, which is restored as instance state on unpickle per
https://docs.python.org/3/library/pickle.html#object.__reduce__.
@allburov allburov merged commit 42bb6f1 into devopshq:master Sep 27, 2024
4 checks passed
@OddBloke OddBloke deleted the oddbloke/pickle branch September 27, 2024 18:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants