[ZODB-Dev] Issue trying to remove elements in OOTreeSet

César Muñoz xcumail at gmail.com
Thu Sep 23 09:54:59 EDT 2010


Hello*,
*I'm having quite a strange problem and I really don't know the reason why
it is occurring.
Briefly, my database is storing data of chat rooms, according to different
indexes (by the user who created the chat room, by the chat room ID, etc).

>From the DB root there's an OOBTree with all the kind of indexes. In this
case I'll focus in the index 'IndexByConf' because it's the one I'll use for
the next examples. Inside IndexByConf there's another OOBTree in which the
keys are the conf ID's. For every conf there's another OOBTree which has a
counter to provide ID's for the conferences and, finally!, a OOTreeSet to
store the chatrooms. So if we want to access the OOTreeSet with the list of
the chatrooms for a given conf, we should do* *
root['indexByConf'][confId]['chatrooms']

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)*

What is the problem? Basically, the chat room IS in the OOTreeSet. If you
list the objects in the set you will see that the memory address of the chat
room i'm trying to delete is contained in the set, but the operator in won't
work. Neither won't the method has_key()
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>

*>>list(root['indexByConf'][confId]['chatrooms'])*
[<MaKaC.plugins.InstantMessaging.handlers.Chatroom object at 0x22ff64ac>,
<MaKaC.plugins.InstantMessaging.handlers.Chatroom object at 0x22ff632c>,
<MaKaC.plugins.InstantMessaging.handlers.Chatroom object at 0x22ff636c>,
<MaKaC.plugins.InstantMessaging.handlers.Chatroom object at 0x22ff63ac>,
<MaKaC.plugins.InstantMessaging.handlers.Chatroom object at 0x22ff646c>,
<MaKaC.plugins.InstantMessaging.handlers.Chatroom object at 0x22ff63ec>,
<MaKaC.plugins.InstantMessaging.handlers.Chatroom object at 0x22ff642c>]

*>>chatroom in root['indexByConf'][confId]['chatrooms']*
False

*>>chatroom in list(root['indexByConf'][confId]['chatrooms']*)
True

*>>root['indexByConf'][confId]['chatrooms'].has_key(chatroom)*
0

*>>chatroom in root['indexByConf'][confId]['chatrooms'].keys()*
True


After this, I switched to a OOBTree instead of a OOTreeSet and I don't get
any exception, but I'd like to avoid using an OOTreeSet in this case.
So do you have any idea of what can be causing this problem?


Best regards,
César.

-- 
César Muñoz

CERN
IT-UDS-AVC-Indico
Bd. 513, R-042
Tel.: +41 22 76 77159
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.zope.org/pipermail/zodb-dev/attachments/20100923/0c72e9e2/attachment.html 


More information about the ZODB-Dev mailing list