[ZODB-Dev] BTrees Bug?

Tim Peters tim at zope.com
Wed Feb 2 11:45:31 EST 2005


[Chris Withers]
> I finally got to the bottom of a long standing nasty little bug, which,
> in short form, looks like this:
>
>>>> from BTrees.IOBTree import IOBTree
> >>> b = IOBTree()
> >>> b[0]=();b[1]=(1,);b[2]=(2,);b[3]=(3,);b[4]=(4,);b[5]=(5,);b[6]=(6,);
> >>> for key in b.keys(0,3):
> ...   print key
> ...   del b[key]
> ... 
> 0 2 4 6
>
> Now, I can see why that happens, once I finally realised what was going
> on, but I have a coupla questions:
>
> 1. What's a better way of doing this? ie: processing a section of a btree
> which may involve deleting some keys? (this behaviour also applies to
> .values(0,x) and .items(0,x))

See the "Iteration and Mutation" section of the ZODB programming guide
(sorry, you'll have to paste this URL together again; or find section 5.3.2
by hand):

<http://zope.org/Wikis/ZODB/FrontPage/guide/node6.html#SECTION00063200000000
0000000>

> 2. The above feels like a bug to me, even excluding the common pythonism
> of not being able to iterate over mutables if you're changing them. The
> above code is saying "gimme keys where the key is less that 3", which it
> doesn't do :-S
>
> What do other people feel about this?

Iteration and mutation don't mix; it's a design limitation, and a
fundamental one; there are no plans to change it; I don't think it would do
anyone real good to change it so that you got back things <= 3 but
nevertheless a seemingly random subset of all that exist; "don't do this".



More information about the ZODB-Dev mailing list