You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Pickled files with pathlib.Path cannot be loaded in py >= 3.13 #133789
In python <=3.12, the resolved path of Path was pathlib.Path, however upon conversion of pathlib into a package now pickle stores the pickled objects as pathlib._local.Path. This leads to backwards incompatibility of files generated with Python >= 3.13. I suppose one can still load pickle files saved using py <= 3.12 into 3.13, but I was wondering if this is as intended.
In retrospect, moving the class definitions to pathlib._local in 3.13 was a mistake. As you point out, it means that path objects pickled in 3.13 can't be unpickled in 3.12. @picnixz do you think we ought to guarantee that works? It's more like forward-compatibility than backward-compatibility I think...
The PR I've logged against this issue doesn't fix the bug reported, instead it fixes a related issue where paths pickled in 3.13 can't be unpickled in 3.14. I misread your report initially, sorry 😅
It's more like forward-compatibility than backward-compatibility I think...
Yes, it's about forward compatibility in this case. So maybe not a real issue (I think we should only guarantee that anything pickled in previous versions should be unpickable in later versions but not the other way around, namely if you pickle something in X.Y, you need at least version X.Y to unpickle it).
I would like to propose a bug fix in Python 3.14.1 to automatically replace the reference. I would like to argue that this is a critical issue with backward compatibility with the standard librar
I read some text above suggesting to fix Python 3.13 the written files, but this would not fix old files that already exist.
Could you please clarify?
I would only be interested in fix for Python 3.14.x, nothing else makes sense.
What does the patch fix, and how do I check out a version with the patch. Happy to test.
IIUC the patch, it should fix issue when you have files from 3.13 version and want to load them in 3.14.
IIUC, to test the linked patch you have to copy _local.py to Lib/pathlib of your local installation.
@sergey-miryanov I just don't know how to get the patch. How this here works. I clicked on all hyper content I could find on this page and don't get anywhere. In circles at best. How can I obtain a patch to try out?
@sergey-miryanov I just copied the contents into the installed ~/Python/lib/python3.14/pathlib directory as _local.py and with that path, loading works fine. Thanks.
I confirm working of the patch.
My apologies I could not quite follow what you wrote earlier at first. Thank you for your patience. The patch is very much appreciated!
Activity
picnixz commentedon May 9, 2025
cc @barneygale
pythonGH-133789: Fix unpickling of pathlib objects pickled in Python …
barneygale commentedon May 10, 2025
In retrospect, moving the class definitions to
pathlib._localin 3.13 was a mistake. As you point out, it means that path objects pickled in 3.13 can't be unpickled in 3.12. @picnixz do you think we ought to guarantee that works? It's more like forward-compatibility than backward-compatibility I think...The PR I've logged against this issue doesn't fix the bug reported, instead it fixes a related issue where paths pickled in 3.13 can't be unpickled in 3.14. I misread your report initially, sorry 😅
picnixz commentedon May 10, 2025
Yes, it's about forward compatibility in this case. So maybe not a real issue (I think we should only guarantee that anything pickled in previous versions should be unpickable in later versions but not the other way around, namely if you pickle something in X.Y, you need at least version X.Y to unpickle it).
Merge branch 'main' into pythongh-133789
2sn commentedon Oct 17, 2025
This issue is still present when I try to load a pickle file in Python 3.14 that was written in Python 3.13.
and then
result
I would like to propose a bug fix in Python 3.14.1 to automatically replace the reference. I would like to argue that this is a critical issue with backward compatibility with the standard librar
2sn commentedon Oct 17, 2025
Obviously, once can work around, but this is not something users should usually have to do ...
sergey-miryanov commentedon Oct 17, 2025
Yes, it is because the proposed PR is not merged yet. Can you please try you example on the liked PR's branch?
2sn commentedon Oct 17, 2025
@sergey-miryanov How would I do this?
I read some text above suggesting to fix Python 3.13 the written files, but this would not fix old files that already exist.
Could you please clarify?
I would only be interested in fix for Python 3.14.x, nothing else makes sense.
What does the patch fix, and how do I check out a version with the patch. Happy to test.
sergey-miryanov commentedon Oct 17, 2025
IIUC the patch, it should fix issue when you have files from 3.13 version and want to load them in 3.14.
IIUC, to test the linked patch you have to copy
_local.pytoLib/pathlibof your local installation.Or you have to wait when PR will be merged.
2sn commentedon Oct 17, 2025
@sergey-miryanov I just don't know how to get the patch. How this here works. I clicked on all hyper content I could find on this page and don't get anywhere. In circles at best. How can I obtain a patch to try out?
sergey-miryanov commentedon Oct 17, 2025
@2sn There is a file Lib/pathlib/_local.py. Please download it and copy to your local installation, as I wrote above.
2sn commentedon Oct 17, 2025
@sergey-miryanov I just copied the contents into the installed
~/Python/lib/python3.14/pathlibdirectory as_local.pyand with that path, loading works fine. Thanks.I confirm working of the patch.
My apologies I could not quite follow what you wrote earlier at first. Thank you for your patience. The patch is very much appreciated!
sergey-miryanov commentedon Oct 17, 2025
Great, thanks!
Merge branch 'main' into pythongh-133789
GH-133789: Fix unpickling of pathlib objects pickled in Python 3.13 (#…
pythonGH-133789: Fix unpickling of pathlib objects pickled in Python …
[3.14] GH-133789: Fix unpickling of pathlib objects pickled in Python…
barneygale commentedon Oct 17, 2025
Sorry for the delay. Fix has landed in main and will be available from 3.14.1.
pythonGH-133789: Fix unpickling of pathlib objects pickled in Python …