From 76b85b3392e5d231b1243a86a6ada5396dfaf72a Mon Sep 17 00:00:00 2001 From: Ross Patterson Date: Mon, 29 Apr 2019 17:06:38 -0700 Subject: [PATCH] Fix missing attributes from old events portlets #305 --- news/305.bugfix | 1 + plone/app/event/upgrades/configure.zcml | 10 +++++ plone/app/event/upgrades/upgrades.py | 54 +++++++++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 news/305.bugfix diff --git a/news/305.bugfix b/news/305.bugfix new file mode 100644 index 000000000..beac3463c --- /dev/null +++ b/news/305.bugfix @@ -0,0 +1 @@ +Fix missing attributes from old events portlets. Fixes a recursion error after upgrading. \ No newline at end of file diff --git a/plone/app/event/upgrades/configure.zcml b/plone/app/event/upgrades/configure.zcml index a51738675..a4cd973bb 100644 --- a/plone/app/event/upgrades/configure.zcml +++ b/plone/app/event/upgrades/configure.zcml @@ -20,6 +20,16 @@ handler=".upgrades.upgrade_attribute_storage" /> + + 0 and len(self.events) + File "src/plone.app.event/plone/app/event/portlets/portlet_events.py", line 154, in events + if ICollection and ICollection.providedBy(self.search_base): + File "src/plone.app.event/plone/app/event/portlets/portlet_events.py", line 122, in search_base + if not self._search_base and self.data.search_base_uid: + File "src/plone.app.event/plone/app/event/portlets/portlet_events.py", line 106, in _uid + path = self.search_base + ... + File "src/plone.app.event/plone/app/event/portlets/portlet_events.py", line 122, in search_base + if not self._search_base and self.data.search_base_uid: + File "src/plone.app.event/plone/app/event/portlets/portlet_events.py", line 106, in _uid + path = self.search_base + RuntimeError: maximum recursion depth exceeded + """ + annotations = IAnnotations(context, None) + if annotations is None: + return + + default_assignment_attrs = vars(portlet_events.Assignment()) + for mapping in annotations.get( + constants.CONTEXT_ASSIGNMENT_KEY, {}).values(): + for assignment in mapping.values(): + if not isinstance(assignment, portlet_events.Assignment): + continue + + attrs = vars(assignment) + for attr, default in default_assignment_attrs.items(): + if attr not in attrs: + setattr(assignment, attr, default) + + +def migrate_portal_events_portlets(context): + """ + Apply the events portlets missing attributes fix to all assignments. + """ + portal = getSite() + migrate_events_portlets(portal) + portal.ZopeFindAndApply( + portal, search_sub=1, apply_func=migrate_events_portlets)