summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorLuke Plant <L.Plant.98@cantab.net>2011-05-30 16:33:23 +0000
committerLuke Plant <L.Plant.98@cantab.net>2011-05-30 16:33:23 +0000
commitdc4c2f3add4f15edf05574e6e8eb101be9da4b90 (patch)
tree9f2df1b1f0b22ba2759e826e67cdf7677ab05c75 /django
parentde3b58d6267a01edefb36c22f80c3399c819d465 (diff)
Fixed #15929 - test.client.RequestFactory keeps state/AuthMiddleware does monkey patching
Thanks to m.vantellingen for the report and tests, and to aaugustin for work on the tests. git-svn-id: http://code.djangoproject.com/svn/django/trunk@16297 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
-rw-r--r--django/contrib/auth/middleware.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/django/contrib/auth/middleware.py b/django/contrib/auth/middleware.py
index c1211c9234..2c19a4e840 100644
--- a/django/contrib/auth/middleware.py
+++ b/django/contrib/auth/middleware.py
@@ -13,7 +13,13 @@ class LazyUser(object):
class AuthenticationMiddleware(object):
def process_request(self, request):
assert hasattr(request, 'session'), "The Django authentication middleware requires session middleware to be installed. Edit your MIDDLEWARE_CLASSES setting to insert 'django.contrib.sessions.middleware.SessionMiddleware'."
- request.__class__.user = LazyUser()
+
+ # We dynamically subclass request.__class__ rather than monkey patch the
+ # original class.
+ class RequestWithUser(request.__class__):
+ user = LazyUser()
+
+ request.__class__ = RequestWithUser
return None