Issue 1592: operations on closed shelves fail cryptically (original) (raw)

Created on 2007-12-11 18:38 by erno, last changed 2022-04-11 14:56 by admin. 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 "", 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
2022-04-11 14:56:28 admin set github: 45933
2008-07-25 18:44:01 rhettinger set status: open -> closedresolution: fixedmessages: +
2008-07-25 18:00:43 rhettinger set files: + shelve.diffkeywords: + patchmessages: +
2008-07-25 17:44:11 loewis set nosy: + loewismessages: +
2008-07-25 16:09:17 rhettinger set assignee: rhettingernosy: + rhettingerversions: - Python 2.5
2008-07-25 15:36:28 tebeka set nosy: + tebekamessages: +
2007-12-12 10:47:47 erno set files: + shelve.diffmessages: +
2007-12-11 20:17:45 christian.heimes set priority: lownosy: + christian.heimesmessages: + versions: + Python 2.6, Python 2.5, Python 3.0, - Python 2.4
2007-12-11 18:38:16 erno create