[Python-bugs-list] [ python-Bugs-744687 ] anydbm and whichdb again

SourceForge.net noreply@sourceforge.net
Sat, 14 Jun 2003 01:18:40 -0700


Bugs item #744687, was opened at 2003-05-28 05:07
Message generated for change (Comment added) made by loewis
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=744687&group_id=5470

Category: Python Library
Group: None
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: Gregory Saunders (grerfy)
Assigned to: Nobody/Anonymous (nobody)
Summary: anydbm and whichdb again

Initial Comment:
There is an annoying inconsistency with the various dbm
modules that occurs when a database is created, left
empty, and then re-opened for writing later with
anydbm. Code to produce the bug appears below:

Python 2.2.2 (#1, Mar 21 2003, 23:01:54) 
[GCC 3.2.3 20030316 (Debian prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for
more information.
>>> import dbhash, gdbm, dumbdbm, anydbm
>>> a = dbhash.open('/tmp/a', 'c')
>>> a.close()
>>> a1 = anydbm.open('/tmp/a', 'w')
>>> a1.close()
>>> b = gdbm.open('/tmp/b', 'c')
>>> b.close()
>>> b1 = anydbm.open('/tmp/b', 'w')
>>> b1.close()
>>> c = dumbdbm.open('/tmp/c', 'c')
>>> c.close()
>>> c1 = anydbm.open('/tmp/c', 'w')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/lib/python2.2/anydbm.py", line 80, in open
    raise error, "need 'c' or 'n' flag to open new db"
anydbm.error: need 'c' or 'n' flag to open new db
>>> 

I have also tried this on python2.3b1, and python2.1.3
- with the same results. The bug occurs apparently
because the whichdb module cannot properly identify an
empty dumbdbm file. So, the bug also occurs in this
example:

Python 2.2.2 (#1, Mar 21 2003, 23:01:54) 
[GCC 3.2.3 20030316 (Debian prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for
more information.
>>> import dumbdbm, anydbm
>>> a = dumbdbm.open('aaa', 'c')
>>> a['abc'] = 'def'
>>> a.close()
>>> b = anydbm.open('aaa', 'w')
>>> del b['abc']
>>> b.close()
>>> c = anydbm.open('aaa', 'w')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/lib/python2.2/anydbm.py", line 80, in open
    raise error, "need 'c' or 'n' flag to open new db"
anydbm.error: need 'c' or 'n' flag to open new db
>>> 

One solution to this might be to place a warning in the
anydbm documentation that leaving a file empty is
invalid. Another possibility is to include some kind of
magic in dumbdbm so that whichdb can identify them. A
patch for the python2.2.2 dumbdbm.py file is attached.

regards
Greg


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

>Comment By: Martin v. Löwis (loewis)
Date: 2003-06-14 10:18

Message:
Logged In: YES 
user_id=21627

Thanks for the bugreport. A third approach is to treat empty
dir/dat files as dumbdbm. This approach has been implemented in

whichdb.py 1.15
test_whichdb.py 1.5
whichdb.py 1.12.8.1


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

Comment By: Gregory Saunders (grerfy)
Date: 2003-05-28 05:25

Message:
Logged In: YES 
user_id=788203

Incidentally, the patch I have attached is designed to work with
no modification to the whichdb module. The whichdb module could
be modified to check for the correct magic - but this could
break
backwards compatibility.


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

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