In auth.signature, the "created_by" field has a "default" attribute, which 
is a function (called "lazy_user") that returns auth.user_id. At the point 
at which the value of the compute field is computed, the row object passed 
to the compute function simply includes the "lazy_user" function as the 
value of the "created_by" field -- the function has not been called and 
returned the auth.user_id value yet (that doesn't happen until after the 
compute fields are computed). In other words, compute field values are 
calculated *before* default functions are called, so compute functions 
should not depend on the values of other fields whose defaults are set via 
a function.

In this case, you have two alternatives:

ret.append(record["created_by"]()) # This calls the lazy_user function, 
which returns auth.user_id

or:

ret.append(auth.user_id) # Just use auth.user_id directly.

Anthony

On Wednesday, June 28, 2017 at 12:30:22 PM UTC-4, Ramos wrote:
>
> Hello i added an authors and readers  computed fields to my table  
>
> db.define_table(
>     'entities',
>    ...
>     Field('authors',compute= lambda r:authors(r)),
> ...
> )
>
> when i save a record i get this 
> : 
> authors : 
> [*<function lazy_user at 0x2d82a28>*]
> created_by : 
> 4L
> created_on : 
> datetime.datetime(2017, 6, 28, 16, 16, 24)
> delete_record : 
> <pydal.helpers.classes.RecordDeleter object at 0x32142d0>
> description : 
> entity : 
> saw
> event : 
> 1903
> id : 
> 401L
> is_active : 
> True
> last_error : 
> modified_by : 
> 4L
> modified_on : 
> datetime.datetime(2017, 6, 28, 16, 16, 24)
> readers : 
> [2L, 1L, 5L, 4L,* <function lazy_user at 0x2d82a28>*]
> status : 
> 8L
> type : 
> 1L
> update_record : 
> <pydal.helpers.classes.RecordUpdater object at 0x3214290>
> uuid : 
> c12ecf01-0d7b-4334-81c9-b7808c8cf7f9
>
> if i go to admin and edit the record and save again the fuction lazy_user 
> goes away..
> Why is this and how to make it save properly in my code?
>
>
> my code...  
>
> def *authors*(record):
>     ret=[]
>     row=db.status(id=record["status"])
>     rule=db.rules(workflow=row["workflow"],step=record["status"])
>     users=get_userIds(rule)
>     for user in users:
>         if not user in ret:
>             ret.append(user)   
>     if ret==[]:
>         ret.append(record["created_by"])    
>     return str(ret)
>
> def get_userIds(rule):
>     ret=[]
>     for membership in rule["authors"]:
>         temp=db(db.auth_membership.group_id==membership).select()
>         for r in temp:
>             ret.append(r["id"])
>     return ret
>
>
> Regards
>

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to