[ZODB-Dev] dict(conn) produces wierd error in ZODB 3.2

Tim Peters tim_one at email.msn.com
Sun May 18 14:53:43 EDT 2003


[Chris Withers]
>  >>> s = FileStorage('e:\\test.fs')
>  >>> from ZODB import DB
>  >>> db = DB(s)
>  >>> conn = db.open()
>  >>> dict(conn)
> Traceback (most recent call last):
>    File "<stdin>", line 1, in ?
>    File "C:\PYTHON22\Lib\site-packages\ZODB\Connection.py", line
> 130, in __getite
> m__
>      p, serial = self._storage.load(oid, self._version)
>    File "C:\PYTHON22\Lib\site-packages\ZODB\FileStorage.py", line
> 657, in load
>      return self._load(oid, version, self._index, self._file)
>    File "C:\PYTHON22\Lib\site-packages\ZODB\FileStorage.py", line
> 629, in _load
>      pos = _index[oid]
>    File "C:\PYTHON22\Lib\site-packages\ZODB\fsIndex.py", line 62,
> in __getitem__
>      return str2num(self._data[key[:6]][key[6:]])
> TypeError: unsubscriptable object
>
> Any ideas?

About what, specifically?  It doesn't make sense to try to do dict(conn), so
it's not surprising that the attempt dies in some way.  It would make sense
to try to do dict(conn.root()), though, so it would be interesting if that
didn't work.

In 2.2, dict() first looks to see whether its argument has a .keys() method.
conn does not.  Then dict() sees whether its argument responds to the
iteration protocol, hoping to create a dict from a sequence of two-item
sequences.  iter(conn) does succeed:

>>> iter(conn)
<iterator object at 0x00F13060>
>>>

This is because, while conn does not support __iter__, conn does support
__getitem__, and for backward compatibility the iteration protocol
synthesizes an iterator for any object that supports __getitem__.  conn
*expects* __getitem__ to be called with oids, though, and the iteration
protocol synthesizes an iterator that passes 0, 1, 2, ... successively to
__getitem__, until IndexError gets raised.  That doesn't make sense for
Connection objects, and it eventually dies in a senseless way (specifically,
key is 0 at the time this dies, and 0 is not subscriptable -- 0 came from
the iterator synthesized due to Connection having a __getitem__ method).

Did you expect dict(conn) *not* to blow up?  If so, what did you think it
would do?  Or is it that you're trying things you know don't make sense, and
just don't like the error msg?




More information about the ZODB-Dev mailing list