[New-bugs-announce] [issue4643] cgitb.html fails if getattr call raises exception

Allan Crooks report at bugs.python.org
Fri Dec 12 15:48:33 CET 2008


New submission from Allan Crooks <amc1 at users.sourceforge.net>:

If cgitb.html tries to get the value of an attribute from an object, and
the getattr call causes an exception to be raised (other than an
AttributeError), then cgitb.html fails to work:

If you run the attached file in Python 2.5.2 or 2.6, you get the
following output:

----

A: the letter a
B:
Something went wrong - attempting to generate HTML stack trace.
Error generating HTML stack trace!
Traceback (most recent call last):
  File "attrtest.py", line 21, in <module>
    html_text = cgitb.html(sys.exc_info())
  File "C:\python26\lib\cgitb.py", line 133, in html
    vars = scanvars(reader, frame, locals)
  File "C:\python26\lib\cgitb.py", line 84, in scanvars
    value = getattr(parent, token, __UNDEF__)
  File "attrtest.py", line 8, in __getattr__
    return str(slf) # Intentional NameError
NameError: global name 'slf' is not defined

----

The problem is in the scanvars function - it offers no protection
against any unexpected exceptions that occur (that escape the getattr
call) - which can be a problem if it is the same problematic code that
caused cgitb.html to be called in the first place.

I think scanvars should catch any exceptions that come from the getattr
call and either mention that the attribute value could not be
determined, or simply omit the mention of the attribute at all.

If the line in the attached file is commented out, then the next line is
caught appropriately and formatted correctly (the offending code occurs
in the same block, but doesn't cause the same problem because it raises
an AttributeError).

----------
components: Library (Lib)
files: attrtest.py
messages: 77672
nosy: amc1
severity: normal
status: open
title: cgitb.html fails if getattr call raises exception
versions: Python 2.5.3, Python 2.6, Python 3.0
Added file: http://bugs.python.org/file12330/attrtest.py

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


More information about the New-bugs-announce mailing list