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.

classification
Title: Unwanted link between volatile and shelve storage
Type: behavior Stage: resolved
Components: Windows Versions: Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: ezio.melotti, r.david.murray, serhiy.storchaka, ttcooper
Priority: normal Keywords:

Created on 2012-11-18 13:38 by ttcooper, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
bugMail.py ttcooper, 2012-11-18 13:38 Contains the TWO files related to reported problem
Messages (8)
msg175871 - (view) Author: Terry Cooper (ttcooper) Date: 2012-11-18 13:38
The Python statement gList1[i1][1] += gList2[i2][1] modifies not only gList1 (a volatile storage object) but dBasis[163] (a record within shelve object dBasis).  Both gList and dBasis[163] are printed before and after execution of the statement by cFract2.combine.  They are obviously not the same record, but the statement modifies gList1[2][1] and dBasis[163][2][1] simultaniously.
msg175903 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2012-11-18 18:55
Any chance you could reduce this to a simpler test case?  It may be a while before anyone gets around to analyzing your complete example.
msg175905 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2012-11-18 19:07
> They are obviously not the same record

Have you tried printing gList1 and dBasis[163], their repr and their ids?
msg175917 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-11-18 20:18
>	dBasis = shelve.open('cFract2.tmp','n')
>	i,testVal,dBasis,oldTime = 0,1,{},int(time.clock())	# Initialize

As I understand, you don't use shelve object at all (except creating an empty base).  Such a lot of code has no relation to the bugs in Python.  Ask on the Python mailing list or on forums and may be someone help you.
msg175919 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2012-11-18 20:23
Indeed.
msg175940 - (view) Author: Terry Cooper (ttcooper) Date: 2012-11-19 01:58
This is easy to reply to.  You better believe I've tried printing gList1 and dBasis[163].  I've also scrapped a predecessor function named combo (which is included in the attachment) and written its successor, viz., "combine".  I bent over backwards to make sure that the two functions did NOTHING the same way.  Guess what.  Both combo and combine screw up exactly the same record that they aren't supposed to know about in exactly the same way.  So I'm pretty sure Python remembers that it originally got one ITEM on gList from dBasis[161].  So I think I know that the problem is to determine WHY Python remembers that.  Of course what oneo thinks one knows is always subject to revision--especially what one thinks one knows about the truth.

--Terry

-----Original Message-----
>From: Ezio Melotti <report@bugs.python.org>
>Sent: Nov 18, 2012 2:07 PM
>To: ttcooper@indy.net
>Subject: [issue16498] Unwanted link between volatile and shelve storage
>
>
>Ezio Melotti added the comment:
>
>> They are obviously not the same record
>
>Have you tried printing gList1 and dBasis[163], their repr and their ids?
>
>----------
>nosy: +ezio.melotti
>
>_______________________________________
>Python tracker <report@bugs.python.org>
><http://bugs.python.org/issue16498>
>_______________________________________
msg175943 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2012-11-19 02:39
If it "got it" from dBasis[163] via item assignment (say gList1[i1][1] = dBasis[163]), then yes, Python remembers that.  Names just hold pointers to objects, so after that assignment gList1[i1][1] points to the same object as dBasis[163] does.  If that object is mutable, and you mutate it (as += will do, if the object is mutable), both names will still reference the same object, the one that has been changed.  

As Serhiy suggested, you are more likely to get help with this on python-list.
msg175945 - (view) Author: Terry Cooper (ttcooper) Date: 2012-11-19 03:04
Got your message before I got his.  Thanks for the reference to python-list.

-----Original Message-----
>From: "R. David Murray" <report@bugs.python.org>
>Sent: Nov 18, 2012 9:39 PM
>To: ttcooper@indy.net
>Subject: [issue16498] Unwanted link between volatile and shelve storage
>
>
>R. David Murray added the comment:
>
>If it "got it" from dBasis[163] via item assignment (say gList1[i1][1] = dBasis[163]), then yes, Python remembers that.  Names just hold pointers to objects, so after that assignment gList1[i1][1] points to the same object as dBasis[163] does.  If that object is mutable, and you mutate it (as += will do, if the object is mutable), both names will still reference the same object, the one that has been changed.  
>
>As Serhiy suggested, you are more likely to get help with this on python-list.
>
>----------
>
>_______________________________________
>Python tracker <report@bugs.python.org>
><http://bugs.python.org/issue16498>
>_______________________________________
History
Date User Action Args
2022-04-11 14:57:38adminsetgithub: 60702
2012-11-19 03:04:48ttcoopersetmessages: + msg175945
2012-11-19 02:39:29r.david.murraysetmessages: + msg175943
2012-11-19 01:58:33ttcoopersetmessages: + msg175940
2012-11-18 20:23:53ezio.melottisetstatus: pending -> closed

messages: + msg175919
stage: resolved
2012-11-18 20:19:25serhiy.storchakasetstatus: open -> pending
resolution: not a bug
2012-11-18 20:18:12serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg175917
2012-11-18 19:07:49ezio.melottisetnosy: + ezio.melotti
messages: + msg175905
2012-11-18 18:55:07r.david.murraysetnosy: + r.david.murray
messages: + msg175903
2012-11-18 13:38:57ttcoopercreate