Thanks Jorge for your answer,
Jorge Godoy a écrit :
> remi jolin <[EMAIL PROTECTED]> writes:
>
>   
>> But I must be wrong !!
>>     
>
> It all depends...  In a standard method with a standard class, the
> objects are flushed. 
>
>
>   
>> Today I wrote a small piece of code to update a data based on the 
>> information received through the URL like this one :
>>     @expose('json', allow_json=True)
>>     
>
> When you say "@expose('json')" you don't need to say "allow_json=True". 
>
>   
Ok.
>>     def store_info(self, id, info):
>>        d = MyData.get(id)
>>         if not d:
>>             return dict(state="Nok")
>>         v = d.value
>>         d.value=info
>>         return dict(state="OK", prev_value=v)
>>
>> If I do http://xxxx:8080/store_info/1/new_data, I get back the json dict 
>> but the data is not updated (if I enable the DB engine echo, I can see 
>> the commit but no update). Is it the normal behavior ?
>> It is only updated if I force a flush (session.flush()) before the return.
>>     
>
> Despise the indentation above be wrong -- I'm assuming it was just a
> copy & paste problem --, it should work.
>
> Can you trascribe the commands issued and shown with the echo from SA? 
>
>   
Here they are :
2007-04-25 08:51:45,478 INFO sqlalchemy.engine.base.Engine.0x..b4 BEGIN
2007-04-25 08:51:45,478 sqlalchemy.engine.base.Engine.0x..b4 INFO BEGIN
2007-04-25 08:51:45,502 INFO sqlalchemy.engine.base.Engine.0x..b4 SELECT 
my_data.id AS my_data_id, my_data.value AS my_data_value
FROM my_data
WHERE my_data.id = ? ORDER BY my_data.oid
2007-04-25 08:51:45,502 sqlalchemy.engine.base.Engine.0x..b4 INFO SELECT 
my_data.id AS my_data_id, my_data.value AS my_data_value
FROM my_data
WHERE my_data.id = ? ORDER BY my_data.oid
2007-04-25 08:51:45,503 INFO sqlalchemy.engine.base.Engine.0x..b4 ['1']
2007-04-25 08:51:45,503 sqlalchemy.engine.base.Engine.0x..b4 INFO ['1']
2007-04-25 08:51:45,510 INFO sqlalchemy.engine.base.Engine.0x..b4 COMMIT
2007-04-25 08:51:45,510 sqlalchemy.engine.base.Engine.0x..b4 INFO COMMIT
192.168.1.136 - - "GET /store_info/1?info=azerty HTTP/1.1" 200 92 "" 
"Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.8.1.3) Gecko/20070309 
Firefox/2.0.0.3"

and the answer on the browser is
{"tg_flash": null, "state": "OK", "prev_value": "aaaaaa"}


If I add a "session.flush()" just before the "return dict(...)" line, I 
get :
2007-04-25 09:03:26,091 INFO sqlalchemy.engine.base.Engine.0x..f4 BEGIN
2007-04-25 09:03:26,091 sqlalchemy.engine.base.Engine.0x..f4 INFO BEGIN
2007-04-25 09:03:26,113 INFO sqlalchemy.engine.base.Engine.0x..f4 SELECT 
my_data.id AS my_data_id, my_data.value AS my_data_value
FROM my_data
WHERE my_data.id = ? ORDER BY my_data.oid
2007-04-25 09:03:26,113 sqlalchemy.engine.base.Engine.0x..f4 INFO SELECT 
my_data.id AS my_data_id, my_data.value AS my_data_value
FROM my_data
WHERE my_data.id = ? ORDER BY my_data.oid
2007-04-25 09:03:26,114 INFO sqlalchemy.engine.base.Engine.0x..f4 ['1']
2007-04-25 09:03:26,114 sqlalchemy.engine.base.Engine.0x..f4 INFO ['1']
2007-04-25 09:03:26,122 INFO sqlalchemy.engine.base.Engine.0x..f4 UPDATE 
my_data SET value=? WHERE my_data.id = ?
2007-04-25 09:03:26,122 sqlalchemy.engine.base.Engine.0x..f4 INFO UPDATE 
my_data SET value=? WHERE my_data.id = ?
2007-04-25 09:03:26,123 INFO sqlalchemy.engine.base.Engine.0x..f4 
['azerty', 1]
2007-04-25 09:03:26,123 sqlalchemy.engine.base.Engine.0x..f4 INFO 
['azerty', 1]
2007-04-25 09:03:26,166 INFO sqlalchemy.engine.base.Engine.0x..f4 COMMIT
2007-04-25 09:03:26,166 sqlalchemy.engine.base.Engine.0x..f4 INFO COMMIT
192.168.1.136 - - "GET /store_info/1?info=azerty HTTP/1.1" 200 57 "" 
"Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.8.1.3) Gecko/20070309 
Firefox/2.0.0.3"



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to