Skip to content

Commit

Permalink
ArtifactoryPath: override PurePath.__reduce__ to fix pickling
Browse files Browse the repository at this point in the history
`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__.
  • Loading branch information
OddBloke authored and allburov committed Sep 27, 2024
1 parent e2d8ce7 commit 42bb6f1
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions artifactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -1565,6 +1565,12 @@ def _init(self, *args, **kwargs):

super(ArtifactoryPath, self)._init(*args, **kwargs)

def __reduce__(self):
# pathlib.PurePath.__reduce__ doesn't include instance state, but we
# have state that needs to be included when pickling
pathlib_reduce = super().__reduce__()
return pathlib_reduce[0], pathlib_reduce[1], self.__dict__

@property
def top(self):
obj = ArtifactoryPath(self.drive)
Expand Down

0 comments on commit 42bb6f1

Please sign in to comment.