Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
request: Move tornado_handler to ZulipRequestNotes.
PIG2085167a93229cb
diff --git a/zerver/decorator.py b/zerver/decorator.pyindex 7e8ea45744e..18c06e93e1c 100644--- a/zerver/decorator.py+++ b/zerver/decorator.py@@ -809,14 +809,14 @@ def internal_notify_view(is_tornado_view: bool) -> Callable[[ViewFuncT], ViewFun) -> HttpResponse:if not authenticate_notify(request):raise AccessDeniedError()- is_tornado_request = hasattr(request, "_tornado_handler")+ request_notes = get_request_notes(request)+ is_tornado_request = request_notes.tornado_handler is not None# These next 2 are not security checks; they are internal# assertions to help us find bugs.if is_tornado_view and not is_tornado_request:raise RuntimeError("Tornado notify view called with no Tornado handler")if not is_tornado_view and is_tornado_request:raise RuntimeError("Django notify view called with Tornado handler")- request_notes = get_request_notes(request)request_notes.requestor_for_logs = "internal"return view_func(request, *args, **kwargs)diff --git a/zerver/lib/test_helpers.py b/zerver/lib/test_helpers.pyindex c40597b695d..7e9d7fdcefc 100644--- a/zerver/lib/test_helpers.py+++ b/zerver/lib/test_helpers.py@@ -323,6 +323,7 @@ class HostRequestMock(HttpRequest):request_notes_map[self] = ZulipRequestNotes(log_data={},+ tornado_handler=DummyHandler(),)@propertydiff --git a/zerver/tests/test_decorators.py b/zerver/tests/test_decorators.pyindex eb7a0e155c5..f1866ac48f3 100644--- a/zerver/tests/test_decorators.py+++ b/zerver/tests/test_decorators.py@@ -54,7 +54,7 @@ from zerver.lib.request import ()from zerver.lib.response import json_response, json_successfrom zerver.lib.test_classes import ZulipTestCase-from zerver.lib.test_helpers import HostRequestMock+from zerver.lib.test_helpers import DummyHandler, HostRequestMockfrom zerver.lib.user_agent import parse_user_agentfrom zerver.lib.users import get_api_keyfrom zerver.lib.utils import generate_api_key, has_api_key_format@@ -1535,7 +1535,7 @@ class TestInternalNotifyView(ZulipTestCase):with self.assertRaises(RuntimeError):self.internal_notify(True, request)- request._tornado_handler = "set"+ get_request_notes(request).tornado_handler = DummyHandler()with self.settings(SHARED_SECRET=secret):self.assertTrue(authenticate_notify(request))self.assertEqual(self.internal_notify(True, request), self.BORING_RESULT)diff --git a/zerver/tornado/handlers.py b/zerver/tornado/handlers.pyindex 88d2b41dea4..914500b017f 100644--- a/zerver/tornado/handlers.py+++ b/zerver/tornado/handlers.py@@ -111,9 +111,12 @@ class AsyncDjangoHandler(tornado.web.RequestHandler, base.BaseHandler):signals.request_started.send(sender=self.__class__)request = WSGIRequest(environ)+ # We do the import during runtime to avoid cyclic dependency+ from zerver.lib.request import get_request_notes+# Provide a way for application code to access this handler# given the HttpRequest object.- request._tornado_handler = self+ get_request_notes(request).tornado_handler = selfreturn requestdiff --git a/zerver/tornado/views.py b/zerver/tornado/views.pyindex 563311447c5..343b68b0a92 100644--- a/zerver/tornado/views.py+++ b/zerver/tornado/views.py@@ -109,7 +109,9 @@ def get_events_backend(raise JsonableError(_("User not authorized for this query"))# Extract the Tornado handler from the request- handler: AsyncDjangoHandler = request._tornado_handler+ tornado_handler = get_request_notes(request).tornado_handler+ assert tornado_handler is not None+ handler: AsyncDjangoHandler = tornado_handlerif user_client is None:valid_user_client = request.client