Cleaning up annotations in Plone's CMFEditions history objects

plone, versioning

Solution

That is nasty. Another reason addons should ONLY use primitive types for all their data storage.

I have some pseudo code that might get you close:

    repo_tool = getToolByName(obj, "portal_repository")
    if not repo_tool.isVersionable(obj):
        return
    history = repo_tool.getHistoryMetadata(obj)
    if not history:
        return       
    length = history.getLength(countPurged=False)
    for i in xrange(length - 1, -1, -1):
        try:
            version = repo_tool.retrieve(obj, i)
            annotations = IAnnotations(version.object)
            del annotations[KEY_TO_DELETE]
        except POSKeyError:
            pass

Problem

I am trying to clean up content annotations (IAnnotations) of uninstalled Plone add-on. I have succefully walked through all site content and removed annotations in live objects. However, CMFEditions / versioning keeps old content copies around and I don't know how to walk through them and remove all bad annotations they have on them. Unless I can clean up these object references, after removing add-on from buildout one starts getting ZODB BrokenObject errors when editing content having annotations with missing objects in history.

Original source