Skip to content

Instantly share code, notes, and snippets.

Created June 12, 2017 13:53
  • Star 2 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save thet/e2c2b7dd6446c55cca9fad67eb6b2856 to your computer and use it in GitHub Desktop.
Plone / Zope Component Architecture: Unregister all broken persistent utilities
# -*- coding: utf-8 -*-
from zope.component.hooks import getSite
import logging
log = logging.getLogger(__name__)
def unregister_broken_persistent_components(context):
portal = getSite()
sm = portal.getSiteManager()
for item in sm._utility_registrations.items():
if hasattr(item[1][0], '__Broken_state__'):
# unregisterUtility(component, provided, name)
# See: five.localsitemanager.registry.PersistentComponents.unregisterUtility # noqa"Unregistering component {0}".format(item))
sm.unregisterUtility(item[1][0], item[0][0], item[0][1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment