Inside a controller.


On Monday, September 24, 2012 3:05:05 PM UTC-5, Massimo Di Pierro wrote:
>
> Can you reproduce this from the shell and/or inside a controller?
>
> On Sunday, 23 September 2012 16:41:15 UTC-5, Massimo Di Pierro wrote:
>>
>> What version are you using?
>>
>> This is what I get:
>>
>> >>> db=DAL()
>> >>> product = db.define_table('product', Field('cost1'), Field('cost2'), 
>> Field('total', compute = lambda r: r['cost1'] + r['cost2']))
>> >>> product.insert(cost1=10, cost2=20)
>> 1
>> >>> p = db.product(1)
>> >>> p.update_record(cost1=5)
>> <Row {'update_record': <gluon.dal.RecordUpdater object at 0x1019bc250>, 
>> 'cost1': 5, 'cost2': '20', 'total': '30', 'id': 1, 'delete_record': 
>> <gluon.dal.RecordDeleter object at 0x1019bc290>}>
>> >>> print db.product[1].total
>> 30
>>
>> On Saturday, 22 September 2012 20:36:44 UTC-5, VP wrote:
>>>
>>> I figured out what I would call a bug.
>>>
>>> I'll give an example:
>>>
>>> Let's say we have this table:
>>>
>>>
>>> product = db.define_table('product', Field('cost1'), Field('cost2'), 
>>> Field('total', compute = lambda r: r['cost1'] + r['cost2']))
>>>
>>>
>>> And if you do this:
>>>
>>> product.insert(cost1=10, cost2=20)
>>> p = db.product(1)
>>> p.update_record(cost1=5)
>>>
>>>
>>> This update won't work.  What is worse is that it fails silently.   The 
>>> reason it won't work is that the row input of the lambda does not have 
>>> "cost2" in it.
>>>
>>> If, however, you do this:
>>>
>>> p.update_record(cost1=5, cost2=p.cost2)
>>>
>>> Then it will work, because now the parameter r (i.e. the row) has both 
>>> cost1 and cost2.
>>>
>>>
>>>
>>> I think it'll be a little tricky for you to fix this, because you 
>>> probably want update to have only relevant fields so that saving to the 
>>> database is effective.   However, this behavior clearly is not desirable.
>>>
>>>
>>>
>>> On Saturday, September 22, 2012 5:23:43 PM UTC-5, Massimo Di Pierro 
>>> wrote:
>>>>
>>>> Can you show us an example?
>>>>
>>>> computed fields usually do not work when there is not enough 
>>>> information to compute. The information must be in the arguments of 
>>>> update_record or update. It will not retrive the info from the database.
>>>>
>>>>
>>>>
>>>>
>>>> On Saturday, 22 September 2012 15:43:59 UTC-5, VP wrote:
>>>>>
>>>>> - sqlite
>>>>> - 2 compute fields do not seem to get call on update using both 
>>>>> update_record and db().update
>>>>> - They do work on crud/form updates though.
>>>>>
>>>>

-- 



Reply via email to