Skip to content. | Skip to navigation

Four Digits | Willemsplein 44, 6811 KD Arnhem, The Netherlands | info@fourdigits.nl
 
Roel Bruggink works for Four Digits and is a Plone developer since 2008. Roel's day-to-day work consists of a wide range of activities linked to Plone; from system administration and backend/frontend development, to project management. Roel currently maintains the collective.anonymousview product.
 

Removing a persistent local utility

by Roel Bruggink Jul 29, 2009

What is the problem?

Trying to remove a local persistent utility using unregisterUtility results in errors like "AttributeError: type object 'IFavoriteStorage' has no attribute '__iro__' ". And above all: no one seems to know how to fix it "properly". Comments are more then welcome!

Solution

There are two parts to the solution: there is the definition of the utility and the utility itself.

1. Unregister the utility (remove defition):

portal.getSiteManager().unregisterUtility(utility, IFavoriteStorage)

2. Delete the object (remove utility itself):

del my_utility

Example

So add or edit Extensions/Install.py and add something like this:

from Products.CMFCore.utils import getToolByName
from Products.CMFPlone.utils import log 
from zope.component import getUtility
from fourdigits.favorites.interfaces import IFavoriteStorage
import transaction

def uninstall(portal, reinstall=False):
    # Remove utilities when really uninstalled
    if not reinstall:
        my_utility = getUtility(IMyFirstUtility)
        portal.getSiteManager().unregisterUtility(my_utility, IFavoriteStorage)
        del my_utility
        transaction.commit()
        log("Uninstalled fourdigits.favorites")
	
    return "Ran all uninstall steps."
 
Godefroid Chapelle

zope.component

Posted by Godefroid Chapelle at Jul 29, 2009 02:47 PM
I think this is related to a bug in the zope.interface registries which would keep some pointer to the Interface classes. It was supposedly fixed by Fred Drake.

http://svn.zope.org/[…]/adapter.py?rev=101362&r1=99411&r2=101362

This was released in 3.5.2. If you could try using that version and confirm it is fixed, it would be nice !
 
Godefroid Chapelle

zope.component

Posted by Godefroid Chapelle at Jul 29, 2009 04:53 PM
I had run into the same type of problem; I had postponed testing that new zope.interface would help in my case. I just did test. It does not help. AFAICS, there is a similar bug in zope.component as there was in zope.interface. I'll keep you informed.
 
Godefroid Chapelle

zope.interface

Posted by Godefroid Chapelle at Jul 29, 2009 05:34 PM
Turns out I spoke to quick : my first test was wrong.

New zope.interface 3.5.2 fixes my issue of a trailing utility interface.
 
Roel Bruggink

Remove

Posted by Roel Bruggink at Sep 09, 2010 10:02 AM
http://pypi.python.org/[…]/1.0a1 should allow you to do this TTW.
 
Made by Four Digits based on Plone.
Made by Four Digits based on Plone.