i suspect it's an order of operations issue.  i'm no expert, but i bet the 
parser parses the function definition when the file is loaded and tries to 
make use of an auth parameter that is not yet initialized.  (the decorator 
is not run until the code is executed....which is sometime after parsing)

perhaps the reason you see this after a few days is because the user got 
logged out due to timeout/session expiration.

given that controller methods can't take parameters.....can't you decorate 
the controller and then not call this method unless you are logged in?  and 
in the method itself make the default for user_id=None and set user_id to 
auth.user.id if user_id is None?

cfh

On Saturday, March 17, 2012 9:54:54 AM UTC-7, backseat wrote:
>
> I have a function whose definition starts as follows:
>
> @auth.requires_login()
> def rbb_time(category_id, from_date, to_date, user_id=auth.user.id):
>
> It works fine. I'll leave the development of this application for a few
> days, come back, run it, and get:
>
> Traceback (most recent call last):
>   File "/home/kae/hg/kae/web2py.1.99.4.pytrack2/gluon/restricted.py", line
>   204, in restricted exec ccode in environment
> File "[...]/controllers/default.py", line 100, in <module> 
>   def rbb_time(category_id, from_date, to_date, user_id=auth.user.id): 
> AttributeError: 'NoneType' object has no attribute 'id'
>
> The only way to fix it (and this isn't 100% reliable) is to comment out
> all of the "@auth.requires_login()" lines, hard-code the above function
> definition to end "user_id=11" (the UID I was logged in as), and then
> call /default/user/logout.
>
> Can anyone offer any suggestions as to what is going on here?
>
> Thanks,
> Keith
>
>

Reply via email to