[issue4643] cgitb.html fails if getattr call raises exception

Allan Crooks report at bugs.python.org
Thu Dec 18 02:43:44 CET 2008


Allan Crooks <amc1 at users.sourceforge.net> added the comment:

In terms of patching scanvars, I came up with the following solution:

ORIGINAL:
if parent is not __UNDEF__:
    value = getattr(parent, token, __UNDEF__)
    vars.append((prefix + token, prefix, value))

SOLUTION:
if parent is not __UNDEF__:
    try:
        value = getattr(parent, token, __UNDEF__)
    except Exception:
        value = __UNDEF__
    vars.append((prefix + token, prefix, value))

I think this makes the most sense - it requires a small change, and it
won't have any strange side effect. One slightly undesirable aspect is
that for an attribute value which could not be determined (due to this
problem), it will say that it was "undefined", which isn't entirely
accurate.

My initial patch changed value to be a string to be "could not determine
value", but if the line of code looked like this:
    print 'B:', weird.b.upper()

Then for something which shouldn't work, it would determine that the
value of weird.b.upper is the string method - which isn't what we're after.

So I would recommend my original patch (as described above) as the best
solution.

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4643>
_______________________________________


More information about the Python-bugs-list mailing list