[ZODB-Dev] Default comparison considered harmful in BTrees.

Jim Fulton jim at zope.com
Wed Oct 27 14:56:44 EDT 2010


On Wed, Oct 27, 2010 at 1:59 PM, Hanno Schlichting <hanno at hannosch.eu> wrote:
> On Wed, Oct 27, 2010 at 6:45 PM, Jim Fulton <jim at zope.com> wrote:
>> If not, I wonder if the existing indexes have some bad values in
>> them that are triggering this somehow.  The relevant check is being done
>> when loading state.  I bet you have some bad keys (e.g. None) in your
>> data structures. Could you check that?  If this is what's happening, then
>> I think the warning is useful.  For 3.11 though (aka trunk) I'll
>> rearrange things
>> so the check isn't performed when loading state.
>
> Aha. I haven't looked into all the cases, but I did find a None value
> in the two examples I checked.
>
> So in an OOTree with string keys, None is considered invalid

Short answer: yes

None's ordering wrt strings can change, and I believe it has in the past.
It compares solely on address.  In Python 3, it is an error to compare None
with something else. Using None as a BTree key seems like a very bad idea.

> and would need to be an empty string?

I suppose that depends on the application.  Was the use of None
intentional, or the result of sloppy coding?

I'm thinking that this change is scary enough that I'm going to separate it
from 3.10.1, especially since 3.10.1 has some other bug fixes that
are pretty important.

I'll make a 3.10.1 release without it and a 3.10.2a1 release with it.

I do think these warnings are beneficial, possibly wildly so. :)
As I said earlier, in 3.11, it will be an error to use an object with
default comparison as a key, but loading state with such objects will
only warn.

Thanks much for trying this out!

Jim

--
Jim Fulton


More information about the ZODB-Dev mailing list