I’ve just started using web2py with Google AppEngine for an app of mine. For some reason, I’m unable to save/retrieve data using the DAL. Here’s the code I’m using:
At the end of db.py:
from aeoid import middleware
from aeoid import users
import json
db.define_table('files',
db.Field('name', 'text'),
db.Field('path', 'text'),
db.Field('version', 'text', default="live"),
db.Field('hash', 'text'),
db.Field('data', 'text'),
db.Field('meta', 'text', default=json.dumps({'date':str(request.now)})),
db.Field('contributors', 'text', default=json.dumps([users.get_current_user()])),
db.Field('lasttime', 'datetime', default=request.now)
)
In my controller:
name = "TEST"
db.files[0] = dict(hash=name, name=name, path=name)
textobj = db.files[1]
if textobj is None:
print "Fail: 500 Internal Server Error"
Here, textobj is always None for some reason.
What am I doing wrong?
EDIT: I’m using AppEngine SDK for Python on Windows.
When using the shortcut syntax
db.table[id],idrefers to the record ID.db.table[0]doesn’t actually refer to an existing record — it is just used to insert a new record.Also, on GAE, the record IDs do not start at 1 and get incremented by 1, so your first inserted record will not have ID=1. You can either do:
or
Finally, before deploying to GAE, make sure you have run the app locally using the GAE SDK appserver in order to properly generate the index.yaml file, as discussed here.