Re: [PATCH django-impersonate] optimization | preserve request.user laziness

Message ID
DKIM signature
Download raw message
In our case that means 100k+ requests every day =)

What do you think about this workaround? I've tested it locally.

class ImpersonateMiddleware(MiddlewareMixin):
    def process_request(self, request):
        _usr = request.user  # save as local var to prevent infinite recursion
        def _get_usr():
            _usr.is_impersonate = False
            return _usr

        request.user = SimpleLazyObject(_get_usr)
        request.impersonator = None

        if '_impersonate' in request.session and request.user.is_authenticated:
Reply to thread Export thread (mbox)