I finally got back to this.  using web2py trunk there was a minor 
modification to dal.py in the attached patch to make the following example 
work:

db.define_table('funtest',
                Field('name', length=128))
def create_one():
    id = request.args[0]
    from google.appengine.ext import db as gae
    class funtest(gae.Expando):
        name = gae.StringProperty(required=False)
    item = funtest(key_name="label:"+id,name='bob')
    item.put()
    return "done"
def read_one():
    id = request.args[0]
    from google.appengine.api.datastore_types import Key
    from google.appengine.ext import db as gae
    key = Key.from_path("funtest","label:"+id)
    #this fails, unknown key exception
    entity_keyid = db.funtest[key]
    entity_keyselect = db(db.funtest.id == key).select().first()
    entity_keyid2 = db.funtest(key) #this returns None
    from google.appengine.ext import db as gae
    entity_gae = gae.get(key)
    return dict(key=key,
                entity_keyselect=entity_keyselect,
                entity_keyid2=entity_keyid2,
                entity_gae=entity_gae)

Note that i had to create_one before i read_one and i have to use the same 
ID arg to each method.  also, if i defined the model class in the same 
method as i was doing the DAL query GAE gets confused because there are 2 
definitions of the same class.  also your other DAL code must not assume 
that the ID for this table is an int (which we often do).  i think it might 
break things like default representations etc.

i suppose the follow-on question is going to be "how do i set a named key 
using DAL".  lemme know if there is interest there and i'll dig into it.

massimo - do you need a google code issue for the patch?  is web2py OK with 
an ID that is a string?  it worked in the simple example but i don't know if 
other features expect the ID field to be an int.

christian

Reply via email to