[issue5754] Shelve module writeback parameter does not act as advertised

Jorge Herskovic report at bugs.python.org
Tue Apr 14 19:03:25 CEST 2009


New submission from Jorge Herskovic <jorge.r.herskovic at uth.tmc.edu>:

The shelve module documentation states that "by default, mutations to
persistent-dictionary mutable entries are not automatically written
back. If the optional writeback parameter is set to True, all entries
accessed are cached in memory, and written back at close time..."
however the implementation's __setitem__ is the following:
    def __setitem__(self, key, value):
        if self.writeback:
            self.cache[key] = value
        f = StringIO()
        p = Pickler(f, self._protocol)
        p.dump(value)
        self.dict[key] = f.getvalue()

which maintains the cache correctly but writes back to the disk on every
operation, violating the writeback documentation. Changing it to 
    def __setitem__(self, key, value):
        if self.writeback:
            self.cache[key] = value
        else:
            f = StringIO()
            p = Pickler(f, self._protocol)
            p.dump(value)
            self.dict[key] = f.getvalue()

seems to match the documentation's intent.

(First report, sorry for any formatting/style issues!)

----------
components: Extension Modules
messages: 85971
nosy: jherskovic
severity: normal
status: open
title: Shelve module writeback parameter does not act as advertised
type: behavior
versions: Python 2.6

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5754>
_______________________________________


More information about the Python-bugs-list mailing list