semidbm icon indicating copy to clipboard operation
semidbm copied to clipboard

Deleting a nonexistent key corrupts the database

Open benrg opened this issue 3 years ago • 0 comments

>>> import semidbm
>>> db = semidbm.open('test', 'n')
>>> del db[b'nonexistent']
Traceback [...]
KeyError: b'nonexistent'
>>> db[b'foo'] = b'bar'
>>> db[b'foo']
b'exi'
>>> db.close()
>>> db = semidbm.open('test', 'r')
Traceback [...]
KeyError: b'nonexistent'

The fix is probably to move the del above the write in _SemiDBM.__delitem__ (and add a regression test).

benrg avatar Jan 06 '22 01:01 benrg