I finally found that the problem was coming from another middleware of
mine:

class AuthRequiredMiddleware(object):
    def process_view(self, request, view_func, view_args,
view_kwargs):
        if request.path.startswith(settings.MEDIA_URL) or request.path
in settings.PUBLIC_PATHS:
            return None
        else:
            return login_required(view_func)(request, *view_args,
**view_kwargs)


I added "request.user.is_authenticated()" in the 'if' statement and
everything worked fine.

class AuthRequiredMiddleware(object):
    def process_view(self, request, view_func, view_args,
view_kwargs):
        if request.user.is_authenticated() or
request.path.startswith(settings.MEDIA_URL) or request.path in
settings.PUBLIC_PATHS:
            return None
        else:
            return login_required(view_func)(request, *view_args,
**view_kwargs)


While I'm happy it's fixed, I don't understand why the fact that the
AuthRequiredMiddleware was returning a 'login_required' function
caused the other middleware not to catch exceptions... :/


On May 24, 8:45 am, Julien <[EMAIL PROTECTED]> wrote:
> Please ignore the "if DEBUG == True: blabla" statement, that was for
> testing. Just consider the list of middlewares above that.
> Don't understand why it doesn't work...
>
> On May 24, 8:41 am, Julien <[EMAIL PROTECTED]> wrote:
>
> > Hi,
>
> > I'm using the middleware from a snippet [1] so I could debug
> > exceptions raised by ajax calls. That snippets simply displays the
> > traceback in the console when an exception occurs:
>
> > class ConsoleExceptionMiddleware:
> >     def process_exception(self, request, exception):
> >         import traceback
> >         import sys
> >         exc_info = sys.exc_info()
> >         print "######################## Exception
> > #############################"
> >         print '\n'.join(traceback.format_exception(*(exc_info or
> > sys.exc_info())))
> >         print
> > "################################################################"
> >         #print repr(request)
> >         #print
> > "################################################################"
>
> > It was working very well for a while, and then I realised it didn't
> > work any more. The middleware is almost never called when an exception
> > is raised (500 error with ajax calls). What is weird is that it does
> > work, but rarely (say one time out of 20), under some conditions that
> > I can't reproduce.
>
> > I don't know what I've done and that caused that strange behaviour.
>
> > Here are my settings:
>
> > MIDDLEWARE_CLASSES = (
> >     'django.middleware.common.CommonMiddleware',
> >     'django.contrib.sessions.middleware.SessionMiddleware',
> >     'django.contrib.auth.middleware.AuthenticationMiddleware',
> >     'django.middleware.doc.XViewMiddleware',
> >     'django.middleware.locale.LocaleMiddleware',
>
> >     'custom_django_utils.middlewares.LoginMessageMiddleware',
>
> >     'commons.middlewares.AuthRequiredMiddleware',
> >     'custom_django_utils.middlewares.ConsoleExceptionMiddleware',
> > )
> > if DEBUG == True:
> >     MIDDLEWARE_CLASSES +=
> > ('custom_django_utils.middlewares.ConsoleExceptionMiddleware',)
>
> > Any idea what's going on?
>
> > Thanks a lot!
>
> > Julien
>
> > [1]http://www.djangosnippets.org/snippets/420/
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to