On 1 Aug 2012, at 8:23 AM, AbrahamLinksys webmas...@icecube.wisc.edu wrote:
I have an appilcation that has been running for a while, and suddenly today
it gave an error on this line in my view:
[a href={{=URL(r=request,args=request.args,vars=dict(all=1)) }}show all
attachements/a]
This worked fine, but then I think I upgraded from 1.99.4 to 1.99.7, and it
throws an error complaining that it cannot concatenate string and int types
(because of dict(all=1) instead of all='1')
That's odd, because by default line 330 should not be being executed (because
url_encode defaults to true). Can you please double-check your
environment/version/etc? The fact that it's exactly line 330 argues that it's
1.99.7, but how do we get there? I just added a handful of unit tests to verify
the expected behavior (temporarily in a scratch copy of 1.99.7; sorry, no
patch), and it checks out OK.
(BTW, that should be show all attachments.)
While it wouldn't hurt to force str(), the idea here is that the only reason
you'd be executing that line is that your vars are *already* url-encoded, which
would mean they're already strings.
Of course, the error can be fixed by passing a string literal or calling
str() on the int, but i was curious if this intended?
I haven't been very careful to only use string vars, assuming that my
laziness would be corrected by some gluonic magic.
Am I supposed to have always been passing only strings as vars? Should I be
proactive and hunt down places in my code in other applications (which are
still using slightly older web2py versions) or is this something that might
change back to being able to use integers?
Just curious. Here's the relevant part of the traceback:
File /usr/web2py-latest/gluon/html.py, line 330, in URL
other += '?%s' % ''.join([var[0]+'='+var[1] for var in list_vars])
TypeError: cannot concatenate 'str' and 'int' objects
If the other+= line were rewritten as such, would it be a bad thing for any
reason?
other += '?%s' % ''.join([str(var[0])+'='+str(var[1]) for var in
list_vars])
Thanks,
Abe
--