Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"root -> root_uid" migration code buggy (at least for the INavigation portlet) #138

Open
d-maurer opened this issue Jun 19, 2020 · 2 comments

Comments

@d-maurer
Copy link

plone.app.portlets.portlets.navigation.Assignment used to following code to migrate from the old toot field to the new root_uid field:

    def _root(self):
        # This is only called if the instance doesn't have a root_uid
        # attribute, which is probably because it has an old 'root'
        # attribute that needs to be converted.
        root = self.root
        if not root:
            return None
        portal = getToolByName(self, 'portal_url').getPortalObject()
        navroot = getNavigationRootObject(self, portal)
        try:
            root = navroot.unrestrictedTraverse(root.lstrip('/'))
        except (AttributeError, KeyError, TypeError, NotFound):
            return
        return root.UID()
    root_uid = ComputedAttribute(_root, 1)

This code fails (to determine the correct root) because getNavigationRootObject returns the portlet assignemt mapping (the parent of the portlet assignment) and nothing fit to perform a tracersal.

@d-maurer
Copy link
Author

In addition: when the Assignment is retrieved by the PortletManagerRetriever, it is not acquisition wrapped. ComputedAttribute(..., 1) requires at least one level of acquisition wrapping to work. This implies that the migration code does not work at all during normal operation.

@aadarsh-nagrath
Copy link
Member

I think using the getNavigationRoot function instead of getNavigationRootObject could work. The getNavigationRoot function returns the navigation root object, whereas getNavigationRootObject returns the portlet assignment mapping. Also we could try wrapping the assignment in an acquisition wrapper before passing it to the ComputedAttribute function

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants