Yeah, I think I'd monkey-patch it.

On Thursday, May 30, 2013 11:15:22 AM UTC-7, Joe Barnhart wrote:
>
> Wow!  I've rediscovered a bug from 2001!  And they say I'm living in the 
> past...
>
> Well at least I'm not alone back there.  Massimo is back there with me!
>
> https://groups.google.com/d/msg/web2py/XF0LbfNl9ag/j2DbOtR1mf0J
>
> On Thursday, May 30, 2013 9:51:05 AM UTC-7, Derek wrote:
>>
>> You ran into a bug (imho) that has existed in python since 2001 (at 
>> least).
>>
>> http://bugs.python.org/issue444913
>>
>> Now it's preserved for backwards compatibility.
>>
>>
>>
>> On Thursday, May 30, 2013 2:06:20 AM UTC-7, Joe Barnhart wrote:
>>>
>>> I've had the most awful time trying to get the actual filename of an 
>>> uploaded file to appear in my database.  I've gone over and over the 
>>> advice, but it has never worked for me.  I was beginning to suspect evil 
>>> spirits in my code when I ran across the problem...
>>>
>>> cgi.FieldStorage does NOT behave like other Python variables in that it 
>>> doesn't resolve to True if the object contains data.  It resolves to False 
>>> ALL THE TIME, whether it has data or not.
>>>
>>> I was dutifully following advice and had code that looked like:
>>>
>>>
>>> if request.vars.upload:
>>>   form.vars.filename = request.vars.upload.filename
>>>
>>>
>>> But guess what?  The code inside "if" NEVER RUNS.
>>>
>>> For now I've worked around it by using the method "has_key()" on the 
>>> cgi.FieldStorage object:
>>>
>>>
>>> if request.vars.has_key('upload'):
>>>   form.vars.filename = request.vars.upload.filename
>>>
>>>
>>>
>>> And this works.
>>>
>>> The "proper" fix is probably to modify cgi.FieldStorage so that is 
>>> resolves to True if it has data and False if empty, like all other Python 
>>> objects.  But I thought I'd pass along my epiphany in case others are 
>>> wondering if their code is inhabited by evil spirits.
>>
>>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to