mozilla/bedrock — pull request #791 by dpoirier (2013-04-19 18:39:20+00:00)
Title: Bug 856919 - Fix request.locale attribute error

pmac opened the bug: We're seeing a few of these per day. I'm still not sure exactly when and why this happens, but it should be easy to fix.

Traceback (most recent call last):
File "/usr/lib64/python2.6/site-packages/newrelic-1.10.2.38/newrelic/hooks/framework_django.py", line 475, in wrapper return wrapped(*args, **kwargs)
File "/data/www/www.mozilla.org-django/bedrock/lib/bedrock_util.py", line 25, in server_error_view return l10n_utils.render(request, template_name)
File "/data/www/www.mozilla.org-django/bedrock/lib/l10n_utils/__init__.py", line 33, in render if request.locale != settings.LANGUAGE_CODE:
AttributeError: 'WSGIRequest' object has no attribute 'locale'

This is happening when the 500 error handler,
bedrock_util.server_error_view, calls our l10n_utils.render method
before the middleware has set the .locale attribute on the request. In
the circumstances, just skip the code that wants the .locale if there
isn't one. We don't want to try anything risky if we're already
handling a 500.