Now its working for all requests, but the solution is a little odd:
First try to get the table, then try to define it for the first time and if 
it fails, try to just define the table, with no migrate. Is this OK?

    def _get_table(self, db, tablename, app):
        tablename = tablename + '_' + app
        logging.info(tablename)
        table = None
        try:
            table = db[tablename]
        except:
            db.rollback()   # not necessary but one day
                            # any app may store tickets on DB
            logging.info("Trying to create")
            try:
                db.define_table(
                    tablename,
                    db.Field('ticket_id', length=100),
                    db.Field('ticket_data', 'text'),
                    db.Field('created_datetime', 'datetime'),
                )
                table = db[tablename]
            except:
                try:
                    db.define_table(
                        tablename,
                        db.Field('ticket_id', length=100),
                        db.Field('ticket_data', 'text'),
                        db.Field('created_datetime', 'datetime'),
                        migrate=False
                    )
                    table = db[tablename]
                except:
                    pass
        return table

On Tuesday, January 8, 2013 4:34:39 PM UTC-2, Felipe Meirelles wrote:
>
> Never mind, this solution just worked the first time, when I need to 
> define the table, the second time it fails too...
>
> On Tuesday, January 8, 2013 4:21:01 PM UTC-2, Felipe Meirelles wrote:
>>
>> Well, the real problem is I'm using GAE with Google Cloud SQL, so I have 
>> the migrations problem but here is the fix:
>>
>> On restricted.py line 72:
>>
>> def _get_table(self, db, tablename, app):
>>         tablename = tablename + '_' + app
>>         try:
>>             table = db[tablename]
>>         except:
>>             db.rollback()   # not necessary but one day
>>                             # any app may store tickets on DB
>>             table = db.define_table(
>>                 tablename,
>>                 db.Field('ticket_id', length=100),
>>                 db.Field('ticket_data', 'text'),
>>                 db.Field('created_datetime', 'datetime'),
>>             )
>>             logging.info(table)
>>         return table
>>
>> The problem is web2py was trying to create the table in every request, 
>> even when it already exists (don't know why, but with lazy tables 
>> db.get(tablename, None) was returning none always). So I swaped to 
>> db[tablename] and added a exception handling for it. Seem to work just fine 
>> now. 
>>
>> Can you take a look and see if this dosen't conflicts with another DBs to 
>> move it to trunk? Thanks!
>>
>> Thanks.
>>
>> On Friday, January 4, 2013 10:58:07 PM UTC-2, Massimo Di Pierro wrote:
>>>
>>> Admin is readonly on GAE and by default not deployed. 
>>>
>>> On Friday, 4 January 2013 17:10:56 UTC-6, Alan Etkin wrote:
>>>>
>>>> El jueves, 3 de enero de 2013 11:31:45 UTC-3, Felipe Meirelles escribió:
>>>>>
>>>>> Well, the problem is when the ticket is saved, self.db points to <DAL 
>>>>> uri="google:sql://******:novello-solutionworkshop:novello-solutionworkshop/novello_test">
>>>>>  
>>>>> but when load() is called, it points to <DAL uri="gae">.
>>>>
>>>>
>>>> AFAIK admin is db less. It uses the db of the app it manages. Besides, 
>>>> wasn't admin disabled for GAE?
>>>>
>>>>

-- 



Reply via email to