4 ms·
Python's truthiness behavior was the trigger for one of my worst ever bugs early in my career, which not only pulled in senior engineering but also marketing/co
by lihaoyi 2y ago
Python's truthiness behavior was the trigger for one of my worst ever bugs early in my career, which not only pulled in senior engineering but also marketing/comms and legal to help sort out the mess. Not a fan!
- adamc 2y agoI think this needs more explanation to know if this is a good argument or not.
- FreakLegion 2y agoKeep in mind that truthiness comes from __bool__ and is overridable, so separate from Python itself, a lot of library authors have made questionable decisions here. A perennial contender is https://github.com/psf/requests/issues/2002 https://github.com/psf/requests/issues/2002.
- aguaviva 2y agoYou know you're going to need to provide us with a little snippet demonstrating this behavior now, right?
- lihaoyi 2y agoI went and dug up the original code that caused an issue. Here it is: https://github.com/python/cpython/blob/v2.7.1/Lib/cgi.py#L602-L603 https://github.com/python/cpython/blob/v2.7.1/Lib/cgi.py#L60... Python's std lib `cgi.FieldStorage` object was falsy if it did not define any headers, even if it contained file data. Thus my conditional trying to check whether a file was being uploaded "if request.field_storage" was going through the False branch when files were being uploaded but only in certain header-free scenarios not covered by automated and manual testing. This resulted in us dropping user data on the floor and losing uploaded files for a very large number of users before we realized and shut it off The other sibling post contains another example where people may be confused, and Google pulls up others. But this is the concrete case that caused us to send out a hundred thousand apology emails to affected customers after losing their files