Comment 1 for bug 311062

Revision history for this message
Philipp von Weitershausen (philikon) wrote : Re: [Bug 311062] [NEW] DefaultTraversable hides the real exception with getattr

On Dec 24, 2008, at 1:18 AM, Edwin Grubbs wrote:
> zope.traversing.adapters.DefaultTraversable.traverse() uses getattr()
> with a default value that hides the real exception. It should call
> getattr() without a default value, so that it can log the actual error
> that occurs.

To my knowledge, getattr(obj, attr, default) will only "eat"
AttributeErrors. If an AttributeError occurs, it'll return the
default. Any other exception should be penetrate to the caller without
any problems. I think this behaviour makes a lot of sense.

So if you're experiencing that getattr() hides a "real" exception in
the code, it seems to me that this exception must be an
AttributeError. But then you'd be out of luck if getattr() didn't use
a default value, because then DeafultTraversable.traverse() would have
to do something like:

   try:
       subobj = getattr(obj, attr)
   except AttributeError:
       ... do something else

So your exception wouldn't be visible anyways.