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: shelve update fails on "large" entry
Type: Stage:
Components: Library (Lib) Versions: Python 2.2
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: brett.cannon, facundobatista, jvickroy
Priority: normal Keywords:

Created on 2002-02-27 15:03 by jvickroy, last changed 2022-04-10 16:05 by admin. This issue is now closed.

Messages (5)
msg9445 - (view) Author: j vickroy (jvickroy) Date: 2002-02-27 15:03
Below is a Python script that demonstrates a possible 
bug when using the shelve module for:
   Python 2.2
   MS Windows 2000 and 98

For 10k, shelve entries, the script works as expected, 
but for 15k entries, an exception is raised 
after "some" number of updates.

I first tried to attach the script but received an 
error.

# begin script
"""
Demonstration of possible update bug using shelve 
module for:
   Python 2.2
   MS Windows 2000 and 98
"""

__author__ = 'jim.vickroy@noaa.gov'

import shelve

def keys():
   return [str(i) for i in range(100)]


def archive():
   return shelve.open('d:/logs/test')


##note = 'x'*10000 # this works 
note = 'x'*15000 # this fails with the following 
exception
"""
Traceback (most recent call last):
  File "C:\PYTHON22\lib\site-
packages\Pythonwin\pywin\framework\scriptutils.py", 
line 301, in RunScript
    exec codeObject in __main__.__dict__
  File "D:\py_trials\shelve_test.py", line 42, in ?
  File "D:\py_trials\shelve_test.py", line 23, in 
update
    db.close()
  File "C:\PYTHON22\lib\shelve.py", line 77, in 
__setitem__
    self.dict[key] = f.getvalue()
error: (0, 'Error')
"""

def update():
   db = archive()
   for this in keys():
      if db.has_key(this):
         entry = db[this]
         entry.append(note)
      else:
         entry = [note]
      db[this] = entry
   db.close()


def validate():
   db = archive()
   actual_keys = db.keys()
   expected_keys = keys()
   assert len(actual_keys) == len(expected_keys), \
      'expected %s -- got %s' % (len(expected_keys), 
len(actual_keys))
   for this in keys():
      entry = db[this]
      assert len(entry) == nbr_of_updates, \
             'expected %s -- got %s' % 
(nbr_of_updates, len(entry))
   db.close()


nbr_of_updates = 10
for i in range(nbr_of_updates):
   update()

validate()

# end script
msg9446 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2003-05-17 01:28
Logged In: YES 
user_id=357491

I actually get a failure with 2.3b1 under OS X at the first assert:

Traceback (most recent call last):
  File "shelve_test.py", line 42, in ?
    validate() 
  File "shelve_test.py", line 30, in validate
    assert len(actual_keys) == len(expected_keys), 'expected %s -- got %s' % 
(len(expected_keys),  
AssertionError: expected 100 -- got 0
msg9447 - (view) Author: Facundo Batista (facundobatista) * (Python committer) Date: 2004-11-25 01:51
Logged In: YES 
user_id=752496

Please, could you verify if this problem persists in Python 2.3.4
or 2.4?

If yes, in which version? Can you provide a test case?

If the problem is solved, from which version?

Note that if you fail to answer in one month, I'll close this bug
as "Won't fix".

Thank you! 

.    Facundo
msg9448 - (view) Author: Facundo Batista (facundobatista) * (Python committer) Date: 2004-11-25 01:51
Logged In: YES 
user_id=752496

Actually, the script you sent is not failing in the way
you're saying. Seems to be another problem, probably in the
script: I have to guess where ident it.

If you post another test case, could it please be more
concise and attach it as a file to this bug?

Thank you!
msg9449 - (view) Author: j vickroy (jvickroy) Date: 2004-11-29 16:17
Logged In: YES 
user_id=17213

this bug does not appear in the following Python version:

'2.3.3 (#51, Dec 18 2003, 20:22:39) [MSC v.1200 32 bit 
(Intel)]'
History
Date User Action Args
2022-04-10 16:05:02adminsetgithub: 36176
2002-02-27 15:03:48jvickroycreate