classification
Title: operations on closed shelves fail cryptically
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.0, Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: christian.heimes, erno, loewis, rhettinger, tebeka
Priority: low Keywords: patch

Created on 2007-12-11 18:38 by erno, last changed 2008-07-25 18:44 by rhettinger. This issue is now closed.

Files
File name Uploaded Description Edit
shelve.diff erno, 2007-12-12 10:47
shelve.diff rhettinger, 2008-07-25 18:00 Alternate patch
Messages (7)
msg58453 - (view) Author: Erno Kuusela (erno) Date: 2007-12-11 18:38
shelve objects set self.dict = 0 in their close() method. this
results in errors such as TypeError: unsubscriptable object and
AttributeError: 'int' object has no attribute 'has_key'.
This is fairly baffling for the user.

"self.dict = 0" in close() is present in current svn trunk too.
msg58463 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2007-12-11 20:17
Can you create a patch? I suggest to use self.dict = None as marker for
a closed shelf.
msg58490 - (view) Author: Erno Kuusela (erno) Date: 2007-12-12 10:47
How about the following patch. With it, you get an IOError.

>>> s = shelve.open('/tmp/t', 'c')
>>> s.has_key('foo')
0
>>> s.close()
>>> s.has_key('foo')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "shelve.py", line 107, in has_key
    return self.dict.has_key(key)
  File "shelve.py", line 94, in getdict
    raise IOError, 'shelf has been closed'
IOError: shelf has been closed
msg70257 - (view) Author: Miki Tebeka (tebeka) * Date: 2008-07-25 15:36
Any reason this is not in trunk yet?
msg70261 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2008-07-25 17:44
The usual reasons, probably: nobody had time to work on it, as there are
so many other things to do.
msg70265 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2008-07-25 18:00
I'm working on this one.  Alternate patch attached.

The problem with the old one is that it slows down every access to the 
shelf and it prevents assignment to self.dict which has always been 
allowed.

The new patch improves error reporting without changing performance or 
semantics for shelves prior to closing.
msg70268 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2008-07-25 18:44
Fixed in r65233
History
Date User Action Args
2008-07-25 18:44:01rhettingersetstatus: open -> closed
resolution: fixed
messages: + msg70268
2008-07-25 18:00:43rhettingersetfiles: + shelve.diff
keywords: + patch
messages: + msg70265
2008-07-25 17:44:11loewissetnosy: + loewis
messages: + msg70261
2008-07-25 16:09:17rhettingersetassignee: rhettinger
nosy: + rhettinger
versions: - Python 2.5
2008-07-25 15:36:28tebekasetnosy: + tebeka
messages: + msg70257
2007-12-12 10:47:47ernosetfiles: + shelve.diff
messages: + msg58490
2007-12-11 20:17:45christian.heimessetpriority: low
nosy: + christian.heimes
messages: + msg58463
versions: + Python 2.6, Python 2.5, Python 3.0, - Python 2.4
2007-12-11 18:38:16ernocreate