[issue37560] with cgi.FieldStorage(...) fails on cleanup with AttributeError, missing try/except in __exit__

Stefanik Gábor report at bugs.python.org
Thu Jul 11 06:02:14 EDT 2019


New submission from Stefanik Gábor <netrolller.3d at gmail.com>:

cgi.FieldStorage has this for its __del__ method:

    def __del__(self):
        try:
            self.file.close()
        except AttributeError:
            pass

By contrast, __exit__ is missing the exception handler:

    def __exit__(self, *args):
        self.file.close()

Because self.file isn't populated in every instance of the FieldStorage class, this can cause FieldStorage to fail with AttributeError when used in a with statement.

----------
components: Library (Lib)
messages: 347667
nosy: Stefanik Gábor
priority: normal
severity: normal
status: open
title: with cgi.FieldStorage(...) fails on cleanup with AttributeError, missing try/except in __exit__
type: behavior
versions: Python 3.7

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37560>
_______________________________________


More information about the Python-bugs-list mailing list