This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: pickle persistent_id return value
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 2.7
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: alexandre.vassalotti Nosy List: alexandre.vassalotti, amaury.forgeotdarc, jcea, pitrou, pschaafsma, python-dev, serhiy.storchaka
Priority: normal Keywords:

Created on 2012-10-14 14:30 by pschaafsma, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (6)
msg172887 - (view) Author: PSchaafsma (pschaafsma) Date: 2012-10-14 14:30
The documentation of persistent_id prescribes that returning None will cause default pickling behavior. This makes sense.

However, in the function in, the return value of persistent_id checked as boolean, causing also return values like 0 and [] to indicate default pickling.

This becomes a problem when unpickleable objects are identified by a simple index in some other list.
msg172975 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2012-10-15 14:36
An easy workaround (and probably the preferred method) it to return a (tag, index) tuple, like the example in

Testing for the None value introduces a slight incompatibility, so IMO it could only be changed for 3.4.
msg172984 - (view) Author: PSchaafsma (pschaafsma) Date: 2012-10-15 15:43
There are indeed many easy workarounds, and we definitely don't want to introduce any incompatibilities. 

I guess the best thing to do is just update the documentation, right?
msg187511 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-04-21 15:19
It was fixed for Python 3 in 0ae50aa7d97c. Should it be fixed in 2.7 too or close the issue as won't fix? Note that cPickle tests the return value of persistent_id only for None.
msg187620 - (view) Author: Alexandre Vassalotti (alexandre.vassalotti) * (Python committer) Date: 2013-04-23 08:44
I think it should be fixed though it is not a high-priority issue.
msg204848 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-11-30 21:24
New changeset ee627983ba28 by Alexandre Vassalotti in branch '2.7':
Issue #16231: Allow false values other than None to be used as persistent IDs.
Date User Action Args
2022-04-11 14:57:37adminsetgithub: 60435
2013-11-30 21:25:08alexandre.vassalottisetstatus: open -> closed
assignee: alexandre.vassalotti
resolution: fixed
stage: resolved
2013-11-30 21:24:51python-devsetnosy: + python-dev
messages: + msg204848
2013-04-23 08:44:33alexandre.vassalottisetmessages: + msg187620
2013-04-21 15:19:27serhiy.storchakasetnosy: + pitrou, serhiy.storchaka, alexandre.vassalotti
messages: + msg187511
2012-10-22 12:43:43jceasetnosy: + jcea
2012-10-15 15:43:10pschaafsmasetmessages: + msg172984
2012-10-15 14:36:40amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg172975
2012-10-14 14:30:17pschaafsmacreate