zope.component: unregisterAdapter uses '==' while the underlying adapter registry uses 'is'

Bug #551049 reported by Marius Gedminas
22
This bug affects 5 people
Affects Status Importance Assigned to Milestone
Zope 3
Won't Fix
Undecided
Unassigned
zope.component
Invalid
Undecided
Unassigned
zope.interface
Won't Fix
Undecided
Unassigned

Bug Description

Try this:

class MyTestClass(PlacelessSetUp):

    def _handler(self, event):
        print "Got event!"

    def test(self):
        sm = zope.component.getGlobalSiteManager()
        sm.registerHandler(self._handler, required=(zope.interface.Interface, ))
        assert sm.unregisterHandler(self._handler, required=(zope.interface.Interface, ))
        zope.event.notify(object())

The assertion will demonstrate that the global site manager thinks it successfully unregistered the adapter, yet the subsequent notify() will invoke our handler.

Why? Because self._handler creates a new bound method instance every time you write that expression. sm.unregisterHandler compares it to the previously registered factory object using '==' which returns true. But then the site manager invokes zope.interface.adapter.BaseAdapterRegistry.unsubscribe, which uses 'is' for identity checking and therefore thinks it got a different handler.

zope.component should use the same kind of check as the underlying implementation, because it now lies to the programmer about unregistering an adapter that really remains registered.

Tres Seaver (tseaver)
Changed in zope3:
status: New → Won't Fix
Revision history for this message
Patrick Gerken (do3cc) wrote :

Trying to reproduce it, I noticed that the code that does not do the proper unregistration is in zope.interface and not in zope.component

Revision history for this message
Tres Seaver (tseaver) wrote :
Changed in zope.interface:
status: New → Won't Fix
Changed in zope.component:
status: New → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.