Comment 2 for bug 311062

Revision history for this message
Edwin Grubbs (edwin-grubbs) wrote : Re: [Bug 311062] [NEW] DefaultTraversable hides the real exception with getattr

On Wed, Dec 24, 2008 at 6:10 AM, Philipp von Weitershausen
<email address hidden> wrote:
> 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.

It's fine that it doesn't allow the AttributeError to percolate up,
but it is not fine that it doesn't log any information about the
exception that it is catching. It is assuming that the AttributeError
just means that the attribute getattr is trying to access doesn't
exist. If the code for a property fails while accessing some other
objects attribute, it would be very useful to see the original
traceback in the log. Instead, I have to add pdb.set_trace()
inside the property that is failing and restart zope. The only
benefit to not logging the traceback from the original exception
is that it makes the error message shorter, which seems hardly
worth it.