mirror of
https://github.com/zulip/zulip.git
synced 2025-11-15 19:31:58 +00:00
tornado: Make process_notification hack avoid import loops.
This fixes a problem where we could not import zerver.lib.streams from zerver.lib.message, which would otherwise be reasonable, because the former implicitly imported many modules due to this issue.
This commit is contained in:
@@ -1329,7 +1329,7 @@ Output:
|
|||||||
# so mypy doesn't allow assigning lst.append to process_notification
|
# so mypy doesn't allow assigning lst.append to process_notification
|
||||||
# So explicitly change parameter name to 'notice' to work around this problem
|
# So explicitly change parameter name to 'notice' to work around this problem
|
||||||
with mock.patch(
|
with mock.patch(
|
||||||
"zerver.tornado.django_api.process_notification", lambda notice: lst.append(notice)
|
"zerver.tornado.event_queue.process_notification", lambda notice: lst.append(notice)
|
||||||
):
|
):
|
||||||
# Some `send_event` calls need to be executed only after the current transaction
|
# Some `send_event` calls need to be executed only after the current transaction
|
||||||
# commits (using `on_commit` hooks). Because the transaction in Django tests never
|
# commits (using `on_commit` hooks). Because the transaction in Django tests never
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ from requests.packages.urllib3.util.retry import Retry
|
|||||||
|
|
||||||
from zerver.lib.queue import queue_json_publish
|
from zerver.lib.queue import queue_json_publish
|
||||||
from zerver.models import Client, Realm, UserProfile
|
from zerver.models import Client, Realm, UserProfile
|
||||||
from zerver.tornado.event_queue import process_notification
|
|
||||||
from zerver.tornado.sharding import get_tornado_port, get_tornado_uri, notify_tornado_queue_name
|
from zerver.tornado.sharding import get_tornado_port, get_tornado_uri, notify_tornado_queue_name
|
||||||
|
|
||||||
|
|
||||||
@@ -127,6 +126,17 @@ def get_user_events(
|
|||||||
|
|
||||||
def send_notification_http(realm: Realm, data: Mapping[str, Any]) -> None:
|
def send_notification_http(realm: Realm, data: Mapping[str, Any]) -> None:
|
||||||
if not settings.USING_TORNADO or settings.RUNNING_INSIDE_TORNADO:
|
if not settings.USING_TORNADO or settings.RUNNING_INSIDE_TORNADO:
|
||||||
|
# To allow the backend test suite to not require a separate
|
||||||
|
# Tornado process, we simply call the process_notification
|
||||||
|
# handler directly rather than making the notify_tornado HTTP
|
||||||
|
# request. It would perhaps be better to instead implement
|
||||||
|
# this via some sort of `responses` module configuration, but
|
||||||
|
# perhaps it's more readable to have the logic live here.
|
||||||
|
#
|
||||||
|
# We use an import local to this function to prevent this hack
|
||||||
|
# from creating import cycles.
|
||||||
|
from zerver.tornado.event_queue import process_notification
|
||||||
|
|
||||||
process_notification(data)
|
process_notification(data)
|
||||||
else:
|
else:
|
||||||
tornado_uri = get_tornado_uri(realm)
|
tornado_uri = get_tornado_uri(realm)
|
||||||
|
|||||||
Reference in New Issue
Block a user