At the time you assign the default value, session.table_token is None, so 
that is the default value. Instead, you can either assign the default value 
after you create the session.table_token, or use a lambda:

db._common_fields.append(Field('request_tenant', default=lambda: 
session.table_token))

Anthony

On Wednesday, January 18, 2012 3:17:55 PM UTC-5, tsvim wrote:
>
> Hi all,
>
> I get the following weird behavior. I defined a common_fields, being 
> request_tenant as such:
>
>
> db._common_fields.append(Field('request_tenant',default=session.table_token,writable=False))
>
> session.table_token is a uuid generated by  the controller.
> There I have the following code:
>
> session.table_token = generate_table_token()
>
> if db(db.table).isempty():
>    field_name = 'MyField'
>    db.table.insert(name=field_name)
>    populate(db.table2,100)
>
> But for some reason it won't take the default value for request_tenant the 
> first time. When I reload the page it creates new entriees with the session 
> variable correct this time.
>
> I suppose session.table_token does not get evaluated when I first generate 
> it, so how can I get the requested behavior? (Both with populate and insert)
>
> Thanks a million for your help,
>
> Tsvi
>

Reply via email to