[ZODB-Dev] odd KeyError in OOSets

Nicholas Henke henken at seas.upenn.edu
Sat Apr 19 00:13:55 EDT 2003


On Fri, 2003-04-18 at 19:00, Tim Peters wrote:
> [Nicholas Henke]
> > Just for fun I printed cmp(object,o) for each o in the OOSet:
> >
> > Obj: <ClubmaskObject node0 at 0x8321008> id: 137498632
> > cmp: 10618
> > Obj: <ClubmaskObject node6 at 0x83368c0> id: 137586880
> > cmp: -1
> > Obj: <ClubmaskObject node3 at 0x8335bd8> id: 137583576
> > cmp: 0
> > Obj: <ClubmaskObject node7 at 0x8337728> id: 137590568
> > cmp: -1
> > Obj: <ClubmaskObject node2 at 0x8338370> id: 137593712
> > cmp: -1
> > Obj: <ClubmaskObject node1 at 0x8339018> id: 137596952
> > cmp: -1
> > Obj: <ClubmaskObject node4 at 0x8339b70> id: 137599856
> > cmp: -1
> >
> > Ok -- so it is in there :/
> 
> This must be a different example than the first one you posted (in that one
> you were looking for something named "node2"; here you're getting a match on
> "node3").
> 

Same example: Upon start, the app updates a field on each of the
objects, which refer to machines, and order is unimportant.

> But the output confirms that you can't use instances of this class in a
> persistent OOSet (see earlier mail) anyway:  the pattern of cmp results
> confirms that the OOSet's elements aren't in sorted order anymore (object >
> node0, and object < node6, but object doesn't lie between node0 and node6).
> That's typical when persistent objects get new memory addresses upon loading
> them from a database and the default __cmp__ is used to compare the
> instances.

That is a fun 'gotcha'. BTW ClubmaskObject(IndexedObject) and
IndexedObject(Persistant), so either Persistant is supposed to provide
__cmp__, or this _really_ needs to be documented somewhere, as any class
that derives from Persistant needs to define __cmp__. I am confused why
cmp returns 0 above ( shows a match ), but the OOSet does not like it. 
Is it complaining because it can't find the object, or what I am
assuming what is happening, where the objects are out of order on
restore, and that makes OOSet really unhappy?

Nic
-- 
Nicholas Henke
Penguin Herder & Linux Cluster System Programmer
Liniac Project - Univ. of Pennsylvania




More information about the ZODB-Dev mailing list