[web2py] .belongs failed on ('item',) to make sure 'item' get interpret as a tuple and not a string

32 views
Skip to first unread message

Richard

unread,
Apr 12, 2013, 1:14:53 PM4/12/13
to web...@googlegroups.com
Hello, 


And open this one to make sure this one doesn't get lost...

You can see my other posts to get more details, but breifely I fall on DAL issue I think with .belongs if for example I only pass a single item to the belongs inside a query... 

I use postgres 9.1 with pgcog2 and web2py 2.3.2

To me .belongs should not failed on a query like this :

db(... & (db.table.field.belongs(request.vars.items)).select(...)

Where request.vars.items may content 1 or more items... So in case there is only one item I could use this work around :

if len(request.vars.items) == 1:
    request.vars.items = (request.vars.items, '')

That work...

But I think DAL need to be fix...

Thanks

Richard

Richard Vézina

unread,
Apr 12, 2013, 1:29:05 PM4/12/13
to web2py-users
It seems that my work around those not work as I expect... :(

Richard



Richard

--
 
---
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 web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Niphlod

unread,
Apr 12, 2013, 3:16:59 PM4/12/13
to web...@googlegroups.com
uhm..... I think that this particular case should be retained as it is: belongs accepts either a list or a set, but not a string, and **should** fail when you pass to it a string instead of a list.

either way your code should do
possible_items = request.vars.items
if isinstance(possible_items, str):
      possible_items = [possible_items]
results = db(db.table.belongs(possible_items))


Richard Vézina

unread,
Apr 12, 2013, 4:54:47 PM4/12/13
to web2py-users
I could do that, but I pass a tuple... I know that an hard parsing since most of the time trailing comma is just strip out I think... I saw a tuple in the DAL : https://code.google.com/p/web2py/source/detail?r=6eed7c7e3ab5

So, I thougth it could take a tuple as well... 

Your solution seems cleaner then a tuple anyway.

Thanks

Richard


Reply all
Reply to author
Forward
0 new messages