TransactionMiddleware assumes that when process_request is called, either process_exception or process_response is guaranteed to be called. This isn't the case if another middleware raises an exception first. If this happens, the call to transaction.enter_transaction_management is not balanced with a call to transaction.leave_transaction_management. This leads to an extremely bad failure mode: transaction management is enabled forever on that thread, which leads to mysterious problems in future requests.
This is a general problem: any middleware might start something that needs guaranteed cleanup at the end of the request, like starting and ending transaction management. I'm not sure what the right solution is. Having BaseHandler.get_response discard exceptions from middleware calls (even if they're logged first) would be bad, but it should be possible for middleware like TransactionMiddleware to guarantee internal consistency, even when another middleware fails. If this is impossible, then it's better to abort angrily, close the thread and force it to be restarted, then to limp on and break mysteriously later. Recovering from unexpected exceptions is a good thing, but half-recovering from them is worse than dying entirely. (This was a pain to diagnose: the transaction containing auth.login()'s session changes was sometimes not being committed, leading to some logins silently returning to the login page. Of course, I saw the middleware exception, but it was triggering on a request that wasn't a concern at the time and I had been ignoring it--and it didn't occur to me that it could cause problems with other requests. Of course, I've fixed my middleware which exposed this problem, but the general problem of clean exception recovery remains.) -- Glenn Maynard --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-developers?hl=en -~----------~----~----~----~------~----~------~--~---