[spambayes-dev] Re: Pickle vs DB inconsistencies

Tim Peters tim.one at comcast.net
Thu Jun 26 01:04:45 EDT 2003


[Tim]
>> You're saying that if d is an open Shelf object, then after
>>
>>     d[string] = whatever
>>
>> the value of the access expression
>>
>>     d[string]
>>
>> is unreliable unless a
>>
>>     d.sync()
>>
>> call intervenes?  That's scary, if so -- or a bug.

[Tony Meyer]
> I believe so.  It's reliable as long as 'string' was already a token,
> but not otherwise.  It doesn't give a random value, at least, it just
> fails to update it.  (So d[string] would return whatever value it had
> before the d[string] = whatever line).

I don't follow this:  if string wasn't already a token, then how could
d[string] have returned *any* value before d[string] was assigned to?  Maybe
I don't understand what you mean by "was already a token".  It would help
most if you could post a tiny self-contained executable program illustrating
what "not reliable" means.  I believe that would be a horrendous bug in the
database package (Python's or Berkeley's, not spambayes's -- the spambayes
storage.py has at least the deleted-word bug I posted about last time).

Here's my failed tiny self-contained attempt at provoking unreliable
behavior (current Python 2.3 CVS on Windows):

>>> import shelve
>>> import bsddb
>>> db = bsddb.hashopen('whatever')
>>> d = shelve.Shelf(db)
>>> d['abc'] = 1, 2
>>> d['abc']
(1, 2)
>>> d['abc'] = 3, 4
>>> d['abc']
(3, 4)
>>> d['x'] = 12
>>> d['x'] = 42
>>> d['x']
42
>>> d['y']
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "C:\CODE\PYTHON\lib\shelve.py", line 118, in __getitem__
    f = StringIO(self.dict[key])
  File "C:\CODE\PYTHON\lib\bsddb\__init__.py", line 86, in __getitem__
    return self.db[key]
KeyError: 'y'
>>>




More information about the spambayes-dev mailing list