[ZODB-Dev] Re: [Zope-dev] [BUG] maybe yet unknown BTREES bug

Chris McDonough chrism@zope.com
24 Jan 2003 18:06:40 -0500


On Fri, 2003-01-24 at 14:36, Dieter Maurer wrote:
> Chris McDonough wrote at 2003-1-24 08:53 -0500:
>  > Tim has fixed lots of bugs in the BTrees code since 2.5.1.  Also, there
>  > were cases in the Transience implementation where I was iterating over
>  > the .keys()/.items()/.values() of an OOBTree or IOBTree and also
>  > mutating its contents, which is disastrous.  Is this one of those cases?
> 
> A "tree[k] = v" should never raise a "KeyError" whatever you are
> doing.

You would think so, but if you do this:

for k in btree.keys():
   btree[k] = 1

... what comes back from "keys()" is not a list or tuple, its a BTreeItems
object, which (from what I understand) itself is a data structure with
pointers into "btree". If you mutate "btree" while iterating over its
keys in this way the pointers in the data structure get out of sync and
don't do what you expect.  It is possible that a KeyError would be raised
in this scenario (maybe not this exact scenario, but one a lot like it).

Cases where I did this in the Transience package have been fixed in CVS.

Good luck in production!

- C