[ZODB-Dev] Weird KeyError with OOBTree

Hanno Schlichting hanno at hannosch.eu
Mon Aug 16 07:32:38 EDT 2010


On Mon, Aug 16, 2010 at 12:14 PM, Pedro Ferreira
<jose.pedro.ferreira at cern.ch> wrote:
> Could this be some problem with using persistent objects as keys in a BTree?
> Some comparison problem?

I'm not entirely sure about this, but I think using persistent objects
as keys isn't supported. Looking at the code, I doubt using anything
expect simple types like unicode strings or tuples of simple types
will work without further work.

>From what I can see in the code, BTree's use functions like
PyObject_Compare to compare different keys. Persistent doesn't
implement any special compare function and falls back to the standard
hash algorithm for an object. This happens to be its memory address.
The memory address obviously changes over time and the same address
gets reused for different objects.

I think implementing a stable hash function for your type could make
this work though.

The ZODB gods correct me please :)

Hanno


More information about the ZODB-Dev mailing list