[ZODB-Dev] Issue trying to remove elements in OOTreeSet
Marius Gedminas
marius at gedmin.as
Thu Sep 23 13:29:25 EDT 2010
On Thu, Sep 23, 2010 at 03:54:59PM +0200, César Muñoz wrote:
> That said, I'm having some problems when removing a chat room from the
> OOTreeSet. Sometimes (and this is weird, sometimes I may get the error, some
> others not) I get a KeyError exception when I try to remove the chat room.
> This is exactly the line that causes the problem:
> *
> root['indexByConf'][confId]['chatrooms'].remove(chatroom)*
...
> However, if you use the keys() method it will work, and if you use the
> operator in with a list of the OOTreeSet it will work also. Take a look at
> what I got from the interpreter:
>
> *
> >>chatroom*
> <MaKaC.plugins.InstantMessaging.handlers.Chatroom object at 0x22ff646c>
It sounds as if your Chatroom class doesn't implement comparison
operators (__lt__ and friends) correctly.
If you want to store objects in an OOTreeSet, those objects must
have a well-defined ordering that doesn't change when the objects are
loaded back from the ZODB and end up at a different memory address. The
default comparison provided by Python doesn't cut it.
So: does your Chatroom define __cmp__ or __lt__, __le__, __gt__, __ge__,
__eq__, __ne__ methods?
Marius Gedminas
--
Writing setattr hooks properly is a black art. Writing persistent
setattr hooks is more like hearding bees blindfolded...
-- Casey Duncan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
Url : http://mail.zope.org/pipermail/zodb-dev/attachments/20100923/c1a7eb7c/attachment.bin
More information about the ZODB-Dev
mailing list