Re: Migrating to BTrees 4.x
"David Glick (Glick Software)" <[email protected]>
| Newsgroups | gmane.comp.web.zope.zodb |
|---|---|
| Message-ID | <[email protected]> |
On 11/19/16 3:58 PM, Jim Fulton wrote: > > > On Sat, Nov 19, 2016 at 3:21 PM, David Glick <[email protected] > <mailto:[email protected]>> wrote: > > I'm working on updating Plone to support ZODB 4 and 5. > > So far most of the blockers are because BTrees 4.x no longer > allows using keys whose ordering is not well-defined, including > None, and there are various places where Plone was using None as a > key. I understand the reason for the restriction and am making > progress on making Plone no longer do this. > > > Hm. IMO, the restriction should be in adding items, not on > unpickling. We should go to great lengths, to avoid unpickling errors. > > I think we should avoid raising this error in __setstate__. It should > be easy to fix. I was hoping you might feel that way. I started implementing the fix and am able to make it ignore the default comparison TypeError during __setstate__. However, even with the state loaded, `__getitem__(None)` and `__delitem__(None)` raise errors, because those operations are checking for keys with default comparison: >>> t = BTrees.OOBTree.OOBTree() >>> bucket_state = ((None, 42),) >>> tree_state = ((bucket_state,),) >>> t.__setstate__(tree_state) >>> t[None] Traceback (most recent call last): File "<stdin>", line 1, in <module> KeyError: None >>> del t[None] Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: Object has default comparison So, still not clear how to remove the `None` key to fix the btree. Well, I guess I can at least construct a replacement BTree by filtering the items now: >>> list(t.items()) [(None, 42)] >>> cleantree = BTrees.OOBTree.OOBTree([(k, v) for k, v in t.items() if t is not None]) David -- You received this message because you are subscribed to the Google Groups "zodb" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.