[Python-bugs-list] [ python-Bugs-654866 ] pickle and cPickle not equivalent

noreply@sourceforge.net noreply@sourceforge.net
Mon, 16 Dec 2002 13:38:08 -0800


Bugs item #654866, was opened at 2002-12-16 15:37
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=654866&group_id=5470

Category: Python Library
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Patrick K. O'Brien (pobrien)
Assigned to: Nobody/Anonymous (nobody)
Summary: pickle and cPickle not equivalent

Initial Comment:
Ignoring cosmetic differences, cPickle is not properly  
pickling references to items in its memo, while pickle  
does the right thing. Attached are two files, created by  
the same process, one using pickle, the other cPickle.  
 
I'll describe the important difference. First we pickle a 
python graph (Bank) that contains references to 
accounts. Then we pickle two transactions 
(DepositOrWithdrawal) that contain references to one of 
the accounts. The pickle version works fine and does a 
get of the account pickled with the Bank: 
 
(ccommands 
DepositOrWithdrawal 
p20 
g2 
Ntp21 
R(dp22 
g6 
F1039911613.244611 
sS'acnt' 
p23 
g13 
sS'amount' 
p24 
I555 
sbp25 
.g0 
(g20 
g2 
Ntp26 
R(dp27 
g6 
F1039911618.384868 
sg23 
g13 
sg24 
I555 
sbp28 
. 
 
But the cPickle version does it wrong. For the first 
transaction it puts a new account instance with a get to 
the dictionary of the account in the Bank. And on 
pickling the second transaction it gets a reference to the 
account instance from the first transaction: 
 
(ccommands 
DepositOrWithdrawal 
p18 
g3 
NtRp19 
(dp20 
g7 
F1039910911.252528 
sS'acnt' 
p21 
(iaccount 
Account 
p22 
g13 
bsS'amount' 
p23 
I555 
sb.g1 
(g18 
g3 
NtRp24 
(dp25 
g7 
F1039910918.068189 
sg21 
g22 
sg23 
I555 
sb. 
 
Let me know if you need more details than this. 

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=654866&group_id=5470