Storing Persistent Objects as keys in BTrees
Hi have problem that appears at random: I store Persistent Objects (inherited from a Zope Folder) as keys in a OOBTree. I developed something like mxmRelation (http://www.zope.org/Members/maxm/productList/mxmRelations) It is strange: I get "r" from the keys of the hash, but if I try to get it from the hash it fails. This only happens sometimes. def tostring(self): "return string of the relations" result={} for r in self._tree.keys(): result[r]=[] hash_back=self._tree.get(r, None) if hash_back==None: print "tostring(): ", r raise Exception, "Internal Error ???" return for r2 in hash_back.keys(): result[r].append(r2) return result It is a single threaded application I use the version for win32: Zope 2.5.0 (binary release, python 2.1, win32-x86), python 2.1.2, win32
Thomas Guettler wrote:
Hi have problem that appears at random:
I store Persistent Objects (inherited from a Zope Folder) as keys in a OOBTree. I developed something like mxmRelation (http://www.zope.org/Members/maxm/productList/mxmRelations)
It is strange: I get "r" from the keys of the hash, but if I try to get it from the hash it fails. This only happens sometimes.
def tostring(self): "return string of the relations" result={} for r in self._tree.keys(): result[r]=[] hash_back=self._tree.get(r, None) if hash_back==None: print "tostring(): ", r raise Exception, "Internal Error ???" return for r2 in hash_back.keys(): result[r].append(r2) return result
It is a single threaded application
Solution: BTrees compare the keys of the objects. This means you have to use keys which can be compared to each other. Since you need to have a __cmp__() method for all objects which can compare all objects with each other it is easier to change the application design and use only one type of object as key. See zodb-dev's thread of this week titled "OOBTree: Persistent Objects as keys" thomas
participants (1)
-
Thomas Guettler