Yes,

Your post reminds me, I forgot something. I thought that when a key_name is 
used, it could simply return that as an id.
But if you say that DAL requires that it returns an integer id, than yes, 
that would break it.
When you use a key_name, the records do not have an numeric id.
But does that mean you should not allow it to be inserted that way?
Nothing restricts users from operating (using web2py api) on rows inserted 
with GAE api....

    
dfields=dict((f.name,self.represent(v,f.type)) for f,v in fields)
        # table._db['_lastsql'] = self._insert(table,fields)
        #quint
        keyname = None
        if 'gae_key_name' in dfields:
            keyname = dfields['gae_key_name']
            if self.use_ndb:
                dfields['id'] = dfields.pop('gae_key_name')
            else:
                dfields['key_name'] = dfields.pop('gae_key_name')


        tmp = table._tableobj(**dfields)
        tmp.put()


        
*if keyname:            return** keyname*


        key = tmp.key if self.use_ndb else tmp.key()
        rid = Reference(key.id() if self.use_ndb else key.id_or_name())
        (rid._table, rid._record, rid._gaekey) = (table, None, key)
        return rid


On Wednesday, January 8, 2014 2:18:53 PM UTC+1, Alan Etkin wrote:
>
>
> I would like to be able to do this using web2py. I could also choose to 
>> use the GAE API directly to do this but then a could not make use thing 
>> like calculated Fields etc in my web2py tables.
>>
>
> One issue about forcing key names is that there's no guarantee that the 
> new key will provide a valid ID integer when retrieved, and the DAL api 
> requires record insertions to provide that kind of value. Note that calls 
> to Key.id() can return None, which is used by the insert method to create 
> the db reference object. IIRC, the exception of that rule is the case of 
> keyed tables, but I'm not if it is supported for gae nosql. In case it is 
> supported, the patch could instead use keyed tables for storing entity key 
> names.
>
> From the datastore Python api:
>
> "... The identifier may be either a *key name* string, assigned 
> explicitly by the application when the instance is created, or an integer 
> *numeric 
> ID,* assigned automatically by App Engine when the instance is written (
> put<https://developers.google.com/appengine/docs/python/datastore/modelclass#Model_put>)
>  
> to the Datastore ..."
>
> I have not tested the behavior but according to the above I think that the 
> datastore api would return None instead of valid integer identifiers for 
> the case of entities stored with manual key names.
>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to