I've opened a new thread, which relates to a previous 
one<https://groups.google.com/forum/#!topic/django-users/Ng0jocuFdqw>from me.
Digging into a wired behaviour in a FormView I've arrived to the following 
problem:
 - In my "form_valid" method I need to manage exceptions situations.
 - 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.

Sometihng like this (I past a simplified version)

class ProjectCreateView(FormView):

    def form_valid(self, form):
        try:
            <something>
        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 crashed seems to be caused 
because of 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




-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to