Presumably session.account is not always defined -- first you have to
save 'account' to the session, so any request before that happens
won't include 'account' in the session.

session is a Storage() object, so when you attempt to access keys that
are not defined, it simply returns None. That's why session.account
doesn't produce an error, even if 'account' hasn't been defined.
However, session.account.id produces an error because session.account
is None, and None does not have an attribute named 'id'.

What do you want the default to be in case there is no 'account' in
session? Maybe something like:

default=session.account and session.account.id or None

Anthony

On Dec 6, 2:06 am, lyn2py <lyn...@gmail.com> wrote:
> Reference post:
> Scope authenticated users in 
> accountshttps://groups.google.com/group/web2py/browse_thread/thread/4e2bfa3f4...
>
> I used fishwebby's method to scope authenticated users. The code used
> is:
>
> >> db._request_tenant = 'account_id'
> >> db._common_fields=[Field('account_id',default=session.account.id, 
> >> writable=False, readable=False)]
>
> But I get this error:
> AttributeError: 'NoneType' object has no attribute 'id'
>
> When I change default to session.account,>> 
> db._common_fields=[Field('account_id',default=session.account, 
> writable=False, readable=False)]
>
> It doesn't give error, but when I use session.account.id or
> session.account['id'] the error comes back.
>
> Because session.account holds all the account info, it is better than
> just to have the id in session.account.
> Is this a bug or must I use session.account to hold only the account
> id?
>
> Or to solve this another way:
> How can I create an accessible "account" variable like "auth", so that
> I can use default=account.id or default=auth.account_id?
>
> Thanks.

Reply via email to