#10378: authenticate() method should not continue on built-in or generic exceptions ---------------------------------------------+------------------------------ Reporter: bendavis78 | Owner: nobody Status: new | Milestone: Component: Authentication | Version: 1.0 Resolution: | Keywords: authenticate TypeError Stage: Design decision needed | Has_patch: 0 Needs_docs: 0 | Needs_tests: 0 Needs_better_patch: 0 | ---------------------------------------------+------------------------------ Comment (by bendavis78):
If anyone's curious about a workaround for this, you can wrap your authenticate to catch the !TypeError. I created a custom exception called "!NextBackend" that I throw if I want the authentication backend to continue, then in the wrapper if a !TypeError is caught, throw it as a "_TypeError" exception so that a real !TypeError is not caught by the core auth code. {{{ #!python class NextBackend(Exception): pass class _TypeError(Exception): pass class MyCustomBackend(ModelBackend): """ Wrapper method for _authenticate(). See http://code.djangoproject.com/ticket/10378 """ def authenticate(self, **kwargs): try: return self._authenticate(**kwargs) except TypeError: e, args, tb = sys.exc_info() raise _TypeError, args, tb except NextBackend: raise TypeError def _authenticate(self, **kwargs): # Your auth code here... if authentication_fails(): raise NextBackend }}} It's fugly but it works :-P -- Ticket URL: <http://code.djangoproject.com/ticket/10378#comment:5> Django <http://code.djangoproject.com/> The Web framework for perfectionists with deadlines. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-updates@googlegroups.com To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-updates?hl=en -~----------~----~----~----~------~----~------~--~---