I would think it would make more sense to use the _before_update callback. 
Then you could simply select the records to be updated and add the relevant 
fields to the update fields before the update happens. Instead, though, I 
would probably just handle it all more explicitly -- before making the 
update, select the records, get all the data necessary for the computed 
fields, and then make the update.

Anthony

On Monday, July 3, 2017 at 12:55:13 PM UTC-4, Ramos wrote:
>
> I´m moving my computed fields from db.entities to another table 
> db.entities_wf_fields and then i use
>
> db.entities_after_update.append(lambda s,f: update_authors(s,f))
> db.entities._after_update.append(lambda s,f: update_readers(s,f))
> etc...
>
> then
> def update_authors(set,ufields):
> record = set.select().first()
>     ...some code....
>      ..some more code...
>        ret= calculating new values for field authors...
> db.entities_wf_fields.update_or_insert((db.entities_wf_fields.entity == 
> record["id"]),entity=record["id"],authors=ret)
> return None
>
> It all happens in the server so it should not be too cpu/db expensive.
>
> I may append around 20 more computed fields like these.. every computed 
> field is a function.
> The issue is that it gets very repeating but.. i need to have those 20 
> computed fields and functions for easy maintenance of each field.
> Am in i the wrong direction ?
>
>
> Regards 
>
>
> 2017-07-03 16:08 GMT+01:00 António Ramos <ramstei...@gmail.com>:
>
>> So should i use instead ?
>> _after_update.append(lambda s,f: function_2_compute_some_fields(s,f))
>> or will i trigger a recursive update and hang the cpu?
>>
>> regards
>>
>> 2017-06-30 19:35 GMT+01:00 Anthony:
>>
>>> On Friday, June 30, 2017 at 11:45:37 AM UTC-4, Ramos wrote:
>>>>
>>>> Another problem or symptom is that the computed function need the 
>>>> record update call to pass all the fields the computed function needs to 
>>>> access otherwise does not  execute.
>>>>
>>>> for example 
>>>>
>>>> my record with id =1
>>>> {"event":"1","created_by":4,"status":21}
>>>>
>>>> this line 
>>>> db(db.entities.id==1).update(event="2",status=21) 
>>>> is different from this line
>>>> db(db.entities.id==1).update(event="2",status=21*,created_by=2*2)
>>>> because passing created_by it allows the computed field to use it if it 
>>>> needs it.It does not receive the full record fields.
>>>>
>>>> Is this  correct or am i missing something?
>>>>
>>>
>>> Yes, that's how it works. The .update() method sends an update query to 
>>> the database -- it does not first select the records from the database 
>>> (which would be inefficient), so it has no access to the current records. 
>>> If you need the current values of some of the fields for the computed field 
>>> to be calculated, then you must first select the records yourself.
>>>
>>> Anthony
>>>
>>> -- 
>>> 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/d/optout.
>>>
>>
>>
>

-- 
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/d/optout.

Reply via email to