From 12265410acda595bfbe65d790a7aa36038379e8c Mon Sep 17 00:00:00 2001
From: Jannis Leidel <jannis@leidel.info>
Date: Fri, 22 Apr 2011 12:15:52 +0000
Subject: [PATCH] Fixed #15672 -- Refined changes made in r15918. Thanks, vung.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16082 bcc190cf-cafb-0310-a4f2-bffc1f526a37
---
 django/core/handlers/modpython.py       | 3 +--
 django/core/handlers/wsgi.py            | 1 -
 tests/regressiontests/handlers/tests.py | 9 +++++++++
 3 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/django/core/handlers/modpython.py b/django/core/handlers/modpython.py
index e5c7467072..f0c77015b4 100644
--- a/django/core/handlers/modpython.py
+++ b/django/core/handlers/modpython.py
@@ -179,11 +179,10 @@ class ModPythonHandler(BaseHandler):
             try:
                 request = self.request_class(req)
             except UnicodeDecodeError:
-                logger.warning('Bad Request (UnicodeDecodeError): %s' % request.path,
+                logger.warning('Bad Request (UnicodeDecodeError)',
                     exc_info=sys.exc_info(),
                     extra={
                         'status_code': 400,
-                        'request': request
                     }
                 )
                 response = http.HttpResponseBadRequest()
diff --git a/django/core/handlers/wsgi.py b/django/core/handlers/wsgi.py
index 058f9c307f..434f91ccf3 100644
--- a/django/core/handlers/wsgi.py
+++ b/django/core/handlers/wsgi.py
@@ -265,7 +265,6 @@ class WSGIHandler(base.BaseHandler):
                     exc_info=sys.exc_info(),
                     extra={
                         'status_code': 400,
-                        'request': request
                     }
                 )
                 response = http.HttpResponseBadRequest()
diff --git a/tests/regressiontests/handlers/tests.py b/tests/regressiontests/handlers/tests.py
index 5e84f71177..40b0a8375a 100644
--- a/tests/regressiontests/handlers/tests.py
+++ b/tests/regressiontests/handlers/tests.py
@@ -1,6 +1,8 @@
 from django.utils import unittest
 from django.conf import settings
 from django.core.handlers.wsgi import WSGIHandler
+from django.test import RequestFactory
+
 
 class HandlerTests(unittest.TestCase):
 
@@ -23,3 +25,10 @@ class HandlerTests(unittest.TestCase):
         # Reset settings
         settings.MIDDLEWARE_CLASSES = old_middleware_classes
 
+    def test_bad_path_info(self):
+        """Tests for bug #15672 ('request' referenced before assignment)"""
+        environ = RequestFactory().get('/').environ
+        environ['PATH_INFO'] = '\xed'
+        handler = WSGIHandler()
+        response = handler(environ, lambda *a, **k: None)
+        self.assertEqual(response.status_code, 400)