Thanks! It works with the query using the "long" syntax: *db(db.table_name.id == key).select().first()* The short version *db.table_name(key)* does returns *None* as it performs a check if key is an integer first. However, using a query instead of a key also works: *db.table_name(db.table_name.id == key)*
The other shortcut *db.table_name[key]* could work if the DAL Table code is altered to detect app engine Key instance. See the patch below (also includes your changes). diff -r 3070c65f3e19 gluon/dal.py --- a/gluon/dal.py Mon Oct 17 08:20:27 2011 -0500 +++ b/gluon/dal.py Mon Oct 17 18:01:14 2011 +0100 @@ -3381,10 +3350,10 @@ def select(self,query,fields,attributes): (items, tablename, fields) = self.select_raw(query,fields,attributes) # self.db['_lastsql'] = self._select(query,fields,attributes) - rows = [ - [t=='id' and (int(item.key().id()) if item.key().id() else - item.key().name()) or getattr(item, t) for t in fields] - for item in items] + rows = [] + for item in items: + row = [t=='id' and item.key().id_or_name() or getattr(item, t) for t in fields] + rows.append(row) colnames = ['%s.%s' % (tablename, t) for t in fields] return self.parse(rows, colnames, False) @@ -4913,13 +4860,13 @@ if rows: return rows[0] return None - elif str(key).isdigit(): + elif str(key).isdigit() or isinstance(key, Key): return self._db(self._id == key).select(limitby=(0,1)).first() elif key: return dict.__getitem__(self, str(key))