BELONGS is not supported on GAE?

75 views
Skip to first unread message

Peter G.

unread,
Feb 21, 2012, 1:06:34 AM2/21/12
to web2py-users
I'm trying to obtain a set of rows whose ID values belongs in rows'
fields of another table.

Here's the code:

# Construct a query to fetch all the mootid's from the group
mootGroup =
db(db.moot_groups.gid==groupid)._select(db.moot_groups.mootid)
# Gets moots only if the moot ID exists in the Group query
moots =
db((db.moots.url==request.get_vars.url)&(db.moots.id.belongs(mootGroup))).select(db.moots.ALL)

The error in the admin says this:
File "/base/data/home/apps/356965595645653415/gluon/dal.py", line
3367, in BELONGS
raise SyntaxError, "Not supported"
SyntaxError: Not supported

Thanks!

guruyaya

unread,
Feb 21, 2012, 2:09:42 AM2/21/12
to web2py-users
I think inner select belongs are not supported by GAE, but using an
array, is. Can anyone confirm what I just said (read the code, didn't
test it).

Peter G.

unread,
Feb 21, 2012, 3:24:38 AM2/21/12
to web2py-users
Hmm, if that's the case, can someone recommend a viable alternative to
perform what I'm trying to do with an operation that works under GAE?

BrendanC

unread,
Feb 21, 2012, 5:02:07 AM2/21/12
to web...@googlegroups.com
I've just started looking Web2py and the Google App Engine - here is some research you might find useful. 

While this does not relate directly to Web2py it's worth reading/reviewing as it illustrates some gae fundamentals.
http://www.arbingersys.com/20080430/google-app-engine-a-better-many-to-many-join.html

Also look at this:

'Belongs' is basically an SQL construct with no GAE counterpart. With GAE you need to rethink your data models and assume you will have some level of data redundancy. 
Note also that the DAL interface to the GAE has some limitations and does not utilitize all the features of the GAE - but that's a separate discussion. Some issues to be aware of are:

- debugging with GAE can be tricky
- not clear if running a local Web2py shell is supported - have not got it to work yet
- expect some surprises along the way to GAE enlightenment

For some decent sample Web2py/GAE code take a look here:

Hope this helps,
BrendanC

howesc

unread,
Feb 21, 2012, 8:05:32 PM2/21/12
to web...@googlegroups.com
what version of web2py are you using?  belongs was not supported on ID at one point, but we fixed that i believe....

anyhow, i would write the queries for GAE like:


# Construct a query to fetch all the mootid's from the group
mootGroup = db(db.moot_groups.gid==groupid).select()
###NOTE: you may only have up to 30 items in a belongs (IN) statement on GAE, you might need to split the following into multiple queries
 
# Gets moots only if the moot ID exists in the Group query
moots = db((db.moots.url==request.get_vars.url)&(db.moots.id.belongs([r.id for r in mootGroup]))).select(db.moots.ALL)

good luck, and ask questions - i'm running several apps of various sizes on GAE so hopefully myself and others can guide you through the GAE pitfalls!

cfh

Peter G.

unread,
Feb 25, 2012, 1:48:25 AM2/25/12
to web2py-users
BrendanC: Thanks for those resources! I ended up gutting that
functionality for now, but those are some great read :)! The non-
relational database backend requires some "unlearning" of SQL database
practices... New challenge for a new environment.

I also have not gotten a local shell working with GAE; it would be
really helpful for interactive development if it existed!

howesc: I'm using the latest stable version (1.99.4). While your
method works as a work around of sorts, it's far too crippled by GAE's
non-relational nature. I would potentially need dozens of queries in
order to fetch all possible mootGroups since GAE limits IN to only 30
items per query! So I simply had to de-normalize the database and gut
the feature I was working on from before.

Thank you both for your helpful replies, I'll definitely be asking
more questions as I hobble along ;)!

howesc

unread,
Feb 25, 2012, 6:56:58 PM2/25/12
to web...@googlegroups.com
yup that happens.  sometimes i will read data into a dict so i can grab more than 30 rows and perform the "join" myself.

i just spent a bunch of time redoing one of my databases to make it more NOSQL happy.
Reply all
Reply to author
Forward
0 new messages