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