[New-bugs-announce] [issue23950] Odd behavior with "file" and "filename" attributes in cgi.FieldStorage

Rob King report at bugs.python.org
Tue Apr 14 18:48:15 CEST 2015

New submission from Rob King:

Hello, everyone.

I've noticed an issue that could be just a documentation inaccuracy or a genuine, minor bug in cgi.FieldStorage.

The documentation for the module states:

"You can test for an uploaded file by testing either the filename attribute or the file attribute."

However, I've noticed that on a form submission that includes both a file field and a normal form field, *all* of the members of the form have a non-None "file" attribute, while only the actual uploaded file has a non-None "filename" attribute.

This would appear to be caused by the cgi module's use of MiniFieldStorage for in some situations, and FieldStorage in others. The FieldStorage class (if I'm reading the code correctly) would appear to always have a non-None "file" attribute but may have a None "filename" attribute.

This makes the documentation for the module unclear, as testing for a non-None "file" attribute will always return True in cases of FieldStorage, even if the particular field is not actually a file.

I would suggest modifying the documentation to say something like:

"You can test for an uploaded file by testing the filename attribute."

Please let me know if I'm missing something, that's always also a possibility. :)

messages: 240942
nosy: deadpixi
priority: normal
severity: normal
status: open
title: Odd behavior with "file" and "filename" attributes in cgi.FieldStorage
versions: Python 3.4

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list