Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Fix cyclic dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
anoadragon453 committed Oct 6, 2020
1 parent 3670fbd commit 5115932
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion synapse/handlers/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
)
Expand Down

0 comments on commit 5115932

Please sign in to comment.