GAE does not support belongs and does not support OR. You have to do:

rows = db(db.media_type.name=='paper').select()&db
(db.media_type.name=='cd').select()

The & is done at the web2py level but since records are exclusive and
you are not sorting them, there is no major slowdown.

Massimo

On Nov 19, 5:49 pm, howesc <[email protected]> wrote:
> Hello,
>
> I'm using Google App Engine, and trying to make use of the new
> 'belongs' feature in queries (thanks much for adding it in!), and am
> having a problem.  It seems that when i construct the query my list is
> being converted to a unicode string, and then the query generation
> code fails.
>
> here's my model:
>
> db.define_table('media_type',
>     Field('name', 'string', notnull=True, unique=True,
>           requires=[IS_NOT_EMPTY(),
>                     IS_NOT_IN_DB(db,'media_type.name')]))
>
> here's my query:
>
>   rows = db(db.media_type.name.belongs(['paper', 'cd'])).select()
>
> here's the error:
>   /cfhowes/clients/rockriver/source/web2py/applications/rockriver/
> controllers/manage.py:song_media", line 68, in song_media\n  File "/
> home/cfhowes/clients/rockriver/source/web2py/gluon/contrib/gql.py",
> line 666, in select\n    (items, tablename, fields) = self._select
> (*fields, **attributes)\n  File "/home/cfhowes/clients/rockriver/
> source/web2py/gluon/contrib/gql.py", line 617, in _select\n    items =
> items.filter(cond, val)\n  File "/home/cfhowes/Desktop/gae/
> google_appengine/google/appengine/ext/db/__init__.py", line 1882, in
> filter\n    raise BadValueError(\'Argument to the "in" operator must
> be a list\')\nBadValueError: Argument to the "in" operator must be a
> list\n
>
> (sorry, it's how i copied it out of the GAE viewer....)
>
> Here's my proposed solution - but I don't understand what i did well
> enough to know the potential other side effects.  If I modify gql.py
> (from Version 1.72.3 (2009-11-10 09:17:13)) and add the following at
> line 460:
>
>         elif isinstance(obj, list):
>             obj = obj
> which keeps the check a few lines later from converting my list to a
> unicode string.  my query now works.
>
> so, did i do something wrong in my query, or is this fix (or something
> similar) needed to make belongs work in the latest build?
>
> thanks,
>
> christian
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to