我有一个非常典型的 view/login_required 装饰器实现,据报告,有时一天两次,QA 团队会遇到这个错误:
ERROR: AttributeError at /plan/reviewplan/1702/ 'WSGIRequest' object has no
attribute 'user' Request Method: GET Request URL:
http://<ip>/plan/reviewplan/1702/ Django Version: 1.5.1
Traceback: File "/usr/lib/pymodules/python2.6/django/core/handlers/base.py" in get_response 187.
response = middleware_method(request, response)
File "/usr/local/lib/python2.6/dist-packages/debug_toolbar/panels/template.py" in process_response 118. pformat(k(self.request))) for k in get_standard_processors()
File "/opt/ion/iondb/rundb/context_processors.py" in base_context_processor 25.
if request.user: Exception Type: AttributeError at /plan/reviewplan/1702/
Exception Value: 'WSGIRequest' object has no attribute 'user'
我检查了一下,视图确实有一个 login_required 装饰器。其他也用 login_required 装饰的视图也有报道。
视图的回报是:
return render_to_response("template.html", context_instance=ctx, mimetype="text/html")
仅供参考: ctx 实例存储在会话中,并且经常在视图调用之间更新。我继承了这个设计,对此我无能为力。处理这个的函数是:
def _create_context_from_session(request, next_step_name):
ctxd = request.session['saved_plan']
ctxd['helper'] = request.session['plan_step_helper']
ctxd['step'] = None
if next_step_name in ctxd['helper'].steps:
ctxd['step'] = ctxd['helper'].steps[next_step_name]
context = RequestContext(request, ctxd)
return context