From 51159325aa7658809f70bcf19502287e7305c72a Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Tue, 6 Oct 2020 18:48:04 +0100 Subject: [PATCH] Fix cyclic dependencies --- synapse/handlers/message.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/synapse/handlers/message.py b/synapse/handlers/message.py index 4793e63b221b..6217e1ab9551 100644 --- a/synapse/handlers/message.py +++ b/synapse/handlers/message.py @@ -59,6 +59,7 @@ from ._base import BaseHandler if TYPE_CHECKING: + from synapse.events.third_party_rules import ThirdPartyEventRules from synapse.server import HomeServer logger = logging.getLogger(__name__) @@ -393,7 +394,7 @@ def __init__(self, hs: "HomeServer"): self.action_generator = hs.get_action_generator() self.spam_checker = hs.get_spam_checker() - self.third_party_event_rules = hs.get_third_party_event_rules() + self.third_party_event_rules = None # type: Optional[ThirdPartyEventRules] self._block_events_without_consent_error = ( self.config.block_events_without_consent_error @@ -891,6 +892,12 @@ async def handle_new_client_event( room_version = await self.store.get_room_version_id(event.room_id) if not ignore_third_party_event_rules: + if not self.third_party_event_rules: + # Only initialise this if necessary. It's possible for ThirdPartyEventRules to call + # this function. However, it should not reach this line. If it does, a cyclic + # dependency will be created. + self.third_party_event_rules = self.hs.get_third_party_event_rules() + event_allowed = await self.third_party_event_rules.check_event_allowed( event, context )