alfonsodg / demo-web2py

Apache License 2.0
0 stars 0 forks source link

table._db['_last_reference'] = tmp is missing from gae insert #183

Closed alfonsodg closed 10 years ago

alfonsodg commented 10 years ago

From dly...@gmail.com on February 07, 2011 05:04:45

What steps will reproduce the problem? 1. write a app for gae which inserts a record into mytable, which returns myrid

  1. try x = myrid._mytable._db._last_reference
  2. observe error

What is the expected output?

myrid._mytable._db._last_reference should work

What do you see instead? code written based on the '_last_reference' mod from June 27, 2010 is broken. What version of the product are you using? On what operating system? Please provide any additional information below. This change was originally put into the trunk on June 27, 2010. It is needed to support creating trees which benefit from the performance of the native gae datastore. Specifically, when creating the root of a tree, we need to get the native ref so that later when leafs are inserted, they have the native ref of the root to use as a backpointer. IMO, the entire DALnr functionality rests on this one line of code. It is the only place in web2py where it is necessary to expose a native reference into the web2py application, that is, upon insert.

The one line of suggested patch is shown below:

 def insert(self,table,fields): 
    dfields=dict((f.name,self.represent(v,f.type)) for f,v in 

fields)

table._db['_lastsql'] = self._insert(table,fields)

    tmp = table._tableobj(**dfields) 
    tmp.put() 
    table._db['_last_reference'] = tmp # suggested patch based on 

June 27/2010 mod in the trunk rid = Reference(tmp.key().id()) (rid._table, rid._record) = (table, None) return rid

Original issue: http://code.google.com/p/web2py/issues/detail?id=185

alfonsodg commented 10 years ago

From massimo....@gmail.com on February 08, 2011 07:30:55

Status: Duplicate