r/Python • • 37m ago

Tutorial A one-line rename in Python 3.15 broke loading of every old pickle

Python 3.15's new sentinel() comes back from a pickle as the same object, which the old object() idiom never did. The catch: it does this by saving its name. Rename MISSING to UNSET and every file saved earlier fails to load.

I wrote up why it happens and the one-line fix: https://www.tk1s.com/python/python-sentinel-rename-breaks-pickle

0 Upvotes

3 comments sorted by

•

u/amarao_san 33m ago

Slop.

•

u/Mother_Day7350 29m ago

Might as well pickle the name at that point.

•

u/really_not_unreal 21m ago

Me when the breaking changes cause breakages.

As per the documentation:

Serialization is a more primitive notion than persistence; although pickle reads and writes file objects, it does not handle the issue of naming persistent objects, nor the (even more complicated) issue of concurrent access to persistent objects

Pickle is a system for serialisation, and while it works for persistence to some extent, it is not ideal for this. The documentation warns about requiring access to the same data structures in order to unpickle them. In essence: you shouldn't be expecting things like this to work. You should instead use the right tool for the job: a database.