id,summary,reporter,owner,description,type,status,component,version,severity,resolution,keywords,cc,stage,has_patch,needs_docs,needs_tests,needs_better_patch,easy,ui_ux 21054,SimpleLazyObject for request.user not correctly evaluated inside RequestContext,Giovanni Allegri,polmuz,"I'm facing a wired behaviour in a FormView: - In my ""form_valid"" method I need to manage exceptions. - In case of an exception I want to pass the response flow to an external method, in an other module. - This external method returns a ""render_to_response"", in which I also pass a RequestContext instance built from the ""FormView.request"" object. - The error template contains the ""user"" variable. I'm doing sometihng like this (I past a simplified version) {{{ class ProjectCreateView(FormView): def form_valid(self, form): try: except IntegrityError as e: return render_error(_('A project with the same title already exists'),self.request) def render_error(msg,request): #__dummy__ = request.user.is_authenticated() data = {'error':{'msg':msg}} return render_to_response('generic_error.html',data,context_instance=RequestContext(request)) }}} This causes a DatabaseError, because it crashes when it reaches the user.is_authenticated template variable. The crashe seems to be caused when the render process tries to access the SimpleLazyObject around the User instance. It seems it's not correctly setup, or whatelse... I don't know. This problem disappears if I use the __dummy__ variable in the previous snippet. This call seems to make the SimpleLazyObject ""prepared"" for later calls (within the context processors). Why does this happen??? It never happens in other view and generic views I'm using in my project. What's wrong with the form view? Notice that 1 - the same happens even if I set self.template_name and call self.render_to_response. 2 - it doesn't happen during the normal form view workflow Giovanni",Bug,closed,Template system,1.5,Normal,needsinfo,"template, form view",,Unreviewed,0,0,0,0,0,0