Ticket #15929: 15929-fix.diff

File 15929-fix.diff, 840 bytes (added by Luke Plant, 9 years ago)

Fix by making AuthenticationMiddleware not do naughty monkey patching

  • django/contrib/auth/middleware.py

    diff -r e752cdf831a7 django/contrib/auth/middleware.py
    a b  
    1313class AuthenticationMiddleware(object):
    1414    def process_request(self, request):
    1515        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'."
    16         request.__class__.user = LazyUser()
     16
     17        # We dynamically subclass request.__class__ rather than monkey patch the
     18        # original class.
     19        class RequestWithUser(request.__class__):
     20            user = LazyUser()
     21
     22        request.__class__ = RequestWithUser
    1723        return None
    1824
    1925
Back to Top