Get the modifying user from instance or middleware.

def get_history_user(self, instance):
        """Get the modifying user from instance or middleware."""
        try:
            return instance._history_user
        except AttributeError:
            request = None
            try:
                if self.thread.request.user.is_authenticated:
                    request = self.thread.request
            except AttributeError:
                pass

        return self.get_user(instance=instance, request=request)