[Python-bugs-list] [ python-Bugs-482460 ] dumbdbm fails to overwrite existing key

noreply@sourceforge.net noreply@sourceforge.net
Fri, 16 Nov 2001 05:22:10 -0800


Bugs item #482460, was opened at 2001-11-16 05:22
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=482460&group_id=5470

Category: Python Library
Group: Python 2.2
Status: Open
Resolution: None
Priority: 5
Submitted By: Michael McCandless (mikemccand)
Assigned to: Nobody/Anonymous (nobody)
Summary: dumbdbm fails to overwrite existing key

Initial Comment:

Here's a simple test case that shows the bug:

  import dumbdbm

  db = dumbdbm.open('db', 'c')
  db['1'] = 'hello'
  db['1'] = 'hello2'
  db.close()

  db = dumbdbm.open('db', 'c')
  print db['1']
  db.close()

This prints out 'hello' but should print out 'hello2'.  As far as I can tell, this bug did not exist 1.5.2, 
but then appeared in 2.0 and is still present  in 2.2b1.

The problem is, when overwriting the key, dumbdbm fails to update the .dir file.  I believe this 
patch fixes the bug:

> diff -c Lib/dumbdbm.py Lib/dumbdbm.py.new 
*** Lib/dumbdbm.py      Tue Sep  4 15:14:13 2001
--- Lib/dumbdbm.py.new  Fri Nov 16 08:16:42 2001
***************
*** 124,129 ****
--- 124,132 ----
              else:
                  pos, siz = self._addval(val)
                  self._index[key] = pos, siz
+             tup = (pos, siz)
+             if self._index[key] != tup:
+                 self._addkey(key, tup)

      def __delitem__(self, key):
          del self._index[key]




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

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