[Zope-dev] Proposed Patch for zope.site

Shane Hathaway shane at hathawaymix.org
Thu Feb 19 01:32:37 EST 2009


Today I ran into an exception masked by Zope 3.  I found the code that 
was masking the exception and fixed it locally, but since this small bit 
of code has no docs or tests, I can't be sure I won't break stuff if I 
check in my change.  What do y'all think I should do?

Here is the patch:


Index: src/zope/site/hooks.py
===================================================================
--- src/zope/site/hooks.py      (revision 96718)
+++ src/zope/site/hooks.py      (working copy)
@@ -91,10 +91,7 @@


  def adapter_hook(interface, object, name='', default=None):
-    try:
-        return siteinfo.adapter_hook(interface, object, name, default)
-    except zope.component.interfaces.ComponentLookupError:
-        return default
+    return siteinfo.adapter_hook(interface, object, name, default)


  def setHooks():



Catching ComponentLookupError is a problem when an adapter factory looks 
up another adapter.  If the first adapter lookup succeeds but the second 
fails with a ComponentLookupError, the current code makes it look like 
the first adapter is not registered at all.  Very confusing.  This patch 
exposes the correct traceback.

I think my patch is correct because the 'default' parameter implies to 
me that if 'siteinfo.adapter_hook' can't find an adapter, it will return 
None, not raise ComponentLookupError.  If 'siteinfo.adapter_hook' does 
in fact raise ComponentLookupError, then something else must be wrong 
and we should report the exception.

BTW, until recently, this module lived in zope.app.component.  It looks 
like this exception masking originated in Subversion revision 26391.

Shane


More information about the Zope-Dev mailing list