Since upgrading to web2py 2.x from 1.9x.x, (I'm running 2.2.1 stable from
source) auth.impersonate isn't working for me any more. My controller
"user.py" has an impersonate action that calls auth.impersonate (first bold
line below):
@auth.requires_login()
def impersonate():
user_id = int(request.args(0))
* imp_form = auth.impersonate(user_id)*
* if not isinstance(imp_form, SQLFORM):*
if user_id == 0:
redirect(URL(c='action1', f='index', args=args,
extension=False))
redirect(URL(c='action2', f='index', args=args, extension=False))
return dict(imp_form=imp_form)
The line
imp_form = auth.impersonate(user_id)
used to work fine but now throws the ticket:
Traceback (most recent call last):
File "N:\web2py\gluon\restricted.py", line 212, in restricted
exec ccode in environment
File "N:/web2py/applications/myapp/controllers/user.py"
<http://127.0.0.1:8000/admin/edit/YAKiToMe/controllers/user.py>, line 674, in
<module>
File "N:\web2py\gluon\globals.py", line 188, in <lambda>
self._caller = lambda f: f()
File "N:\web2py\gluon\tools.py", line 2911, in f
return action(*a, **b)
File "N:/web2py/applications/myapp/controllers/user.py"
<http://127.0.0.1:8000/admin/edit/YAKiToMe/controllers/user.py>, line 555, in
impersonate
imp_form = auth.impersonate(user_id)
File "N:\web2py\gluon\tools.py", line 2826, in impersonate
return SQLFORM(table_user, user.id, readonly=True)
UnboundLocalError: local variable 'user' referenced before assignment
I've traced it in eclipse and user_id is set properly.
I went into gluon/tools.py and hacked line 2826 to be
return SQLFORM(table_user, user_id, readonly=True)
and that resolves the ticket. However, the "not isinstance(imp_form, SQLFORM)"
clause (see emboldened text above) isn't triggering any longer, so I'm not
getting the expected redirection after impersonation.
Any help would be appreciated. Thanks.
--