[Python-bugs-list] [Bug #124367] problem with shelve not handling some db entries.

noreply@sourceforge.net noreply@sourceforge.net
Mon, 4 Dec 2000 05:41:05 -0800


Bug #124367, was updated on 2000-Dec-04 04:57
Here is a current snapshot of the bug.

Project: Python
Category: Modules
Status: Closed
Resolution: Invalid
Bug Group: Not a Bug
Priority: 5
Submitted by: sjordan
Assigned to : Nobody
Summary: problem with shelve not handling some db entries.

Details: I've had a problem with shelve not handling specific database requests.
For example:

>>> import shelve
>>> x = shelve.open('testshelve')
>>> x['test'] = {}
>>> x['test']['foobar'] = 'unf'
>>> x['test']
{}
>>> 

yet it works fine if I do:

>>> x['test'] = {'foobar':'unf'}
>>> x['test']                   
{'foobar': 'unf'}
>>> 

this was using python2.0 on redhat linux 7.0 and also tried on
freebsd4 running python2.0.

Follow-Ups:

Date: 2000-Dec-04 05:41
By: gvanrossum

Comment:
This is not a bug, but a logical conclusion of how shelves work. The shelf object only sees setitem and getitem requests -- it doesn't see modifications to objects retrieved from it.

In particular, x['test']['foobar'] = 'unf' *retrieves* x['test'] and copies it into an anonymous local dictionary, which is then modified and forgotten about -- it is never written back to the shelf using x['test'] = ...

If you need to do this, try:

dict = x['test']
dict['foobar'] = 'unf'
x['test'] = dict

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

For detailed info, follow this link:
http://sourceforge.net/bugs/?func=detailbug&bug_id=124367&group_id=5470