From e3ec20309d1aabed880fb8bcfe84747e9252e884 Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Tue, 9 Feb 2021 14:29:03 -0500 Subject: [PATCH 1/7] Add types for federation handler. --- synapse/federation/sender/__init__.py | 4 ++-- synapse/notifier.py | 5 ++++- synapse/replication/tcp/handler.py | 5 ++++- synapse/server.py | 14 +++++++++----- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/synapse/federation/sender/__init__.py b/synapse/federation/sender/__init__.py index 643b26ae6d2d..7107e5a641e0 100644 --- a/synapse/federation/sender/__init__.py +++ b/synapse/federation/sender/__init__.py @@ -472,10 +472,10 @@ async def send_presence(self, states: List[UserPresenceState]): self._processing_pending_presence = False def send_presence_to_destinations( - self, states: List[UserPresenceState], destinations: List[str] + self, states: List[UserPresenceState], destinations: Iterable[str] ) -> None: """Send the given presence states to the given destinations. - destinations (list[str]) + destinations """ if not states or not self.hs.config.use_presence: diff --git a/synapse/notifier.py b/synapse/notifier.py index 0745899b480b..2f59151b12e7 100644 --- a/synapse/notifier.py +++ b/synapse/notifier.py @@ -37,6 +37,7 @@ from synapse.api.constants import EventTypes, HistoryVisibility, Membership from synapse.api.errors import AuthError from synapse.events import EventBase +from synapse.federation.sender import FederationSender from synapse.handlers.presence import format_user_presence_state from synapse.logging.context import PreserveLoggingContext from synapse.logging.utils import log_function @@ -217,7 +218,9 @@ def __init__(self, hs: "synapse.server.HomeServer"): self.federation_sender = None if hs.should_send_federation(): - self.federation_sender = hs.get_federation_sender() + federation_sender = hs.get_federation_sender() + assert isinstance(federation_sender, FederationSender) + self.federation_sender = federation_sender self.state_handler = hs.get_state_handler() diff --git a/synapse/replication/tcp/handler.py b/synapse/replication/tcp/handler.py index 8ea8dcd587c5..a6873faaa416 100644 --- a/synapse/replication/tcp/handler.py +++ b/synapse/replication/tcp/handler.py @@ -34,6 +34,7 @@ from twisted.internet.protocol import ReconnectingClientFactory +from synapse.federation.send_queue import FederationRemoteSendQueue from synapse.metrics import LaterGauge from synapse.metrics.background_process_metrics import run_as_background_process from synapse.replication.tcp.client import DirectTcpReplicationClientFactory @@ -214,7 +215,9 @@ def __init__(self, hs: "HomeServer"): self._federation_sender = None if self._is_master and not hs.config.send_federation: - self._federation_sender = hs.get_federation_sender() + federation_sender = hs.get_federation_sender() + assert isinstance(federation_sender, FederationRemoteSendQueue) + self._federation_sender = federation_sender self._server_notices_sender = None if self._is_master: diff --git a/synapse/server.py b/synapse/server.py index 6b3892e3cdff..06946672c1c8 100644 --- a/synapse/server.py +++ b/synapse/server.py @@ -425,7 +425,7 @@ def get_presence_handler(self) -> PresenceHandler: return PresenceHandler(self) @cache_in_self - def get_typing_handler(self): + def get_typing_handler(self) -> Union[TypingWriterHandler, FollowerTypingHandler]: if self.config.worker.writers.typing == self.get_instance_name(): return TypingWriterHandler(self) else: @@ -569,7 +569,9 @@ def get_federation_transport_client(self) -> TransportLayerClient: return TransportLayerClient(self) @cache_in_self - def get_federation_sender(self): + def get_federation_sender( + self, + ) -> Union[FederationSender, FederationRemoteSendQueue]: if self.should_send_federation(): return FederationSender(self) elif not self.config.worker_app: @@ -648,13 +650,15 @@ def get_federation_registry(self) -> FederationHandlerRegistry: return FederationHandlerRegistry(self) @cache_in_self - def get_server_notices_manager(self): + def get_server_notices_manager(self) -> ServerNoticesManager: if self.config.worker_app: raise Exception("Workers cannot send server notices") return ServerNoticesManager(self) @cache_in_self - def get_server_notices_sender(self): + def get_server_notices_sender( + self, + ) -> Union[WorkerServerNoticesSender, ServerNoticesSender]: if self.config.worker_app: return WorkerServerNoticesSender(self) return ServerNoticesSender(self) @@ -758,7 +762,7 @@ def get_outbound_redis_connection(self) -> Optional["RedisProtocol"]: reconnect=True, ) - async def remove_pusher(self, app_id: str, push_key: str, user_id: str): + async def remove_pusher(self, app_id: str, push_key: str, user_id: str) -> None: return await self.get_pusherpool().remove_pusher(app_id, push_key, user_id) def should_send_federation(self) -> bool: From 872380d5277418303729f48b0caa596cd1baf7b0 Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Tue, 9 Feb 2021 14:29:33 -0500 Subject: [PATCH 2/7] Add type hints to groups server handler. --- synapse/handlers/groups_local.py | 6 ++++++ synapse/server.py | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/synapse/handlers/groups_local.py b/synapse/handlers/groups_local.py index 71f11ef94aad..f64335f4b704 100644 --- a/synapse/handlers/groups_local.py +++ b/synapse/handlers/groups_local.py @@ -18,6 +18,7 @@ from typing import TYPE_CHECKING, Dict, Iterable, List, Set from synapse.api.errors import HttpResponseException, RequestSendFailed, SynapseError +from synapse.groups.groups_server import GroupsServerHandler from synapse.types import GroupID, JsonDict, get_domain_from_id if TYPE_CHECKING: @@ -289,6 +290,7 @@ async def create_group( logger.info("Asking to create group with ID: %r", group_id) if self.is_mine_id(group_id): + assert isinstance(self.groups_server_handler, GroupsServerHandler) res = await self.groups_server_handler.create_group( group_id, user_id, content ) @@ -317,6 +319,7 @@ async def join_group( """Request to join a group """ if self.is_mine_id(group_id): + assert isinstance(self.groups_server_handler, GroupsServerHandler) await self.groups_server_handler.join_group(group_id, user_id, content) local_attestation = None remote_attestation = None @@ -364,6 +367,7 @@ async def accept_invite( """Accept an invite to a group """ if self.is_mine_id(group_id): + assert isinstance(self.groups_server_handler, GroupsServerHandler) await self.groups_server_handler.accept_invite(group_id, user_id, content) local_attestation = None remote_attestation = None @@ -412,6 +416,7 @@ async def invite( """ content = {"requester_user_id": requester_user_id, "config": config} if self.is_mine_id(group_id): + assert isinstance(self.groups_server_handler, GroupsServerHandler) res = await self.groups_server_handler.invite_to_group( group_id, user_id, requester_user_id, content ) @@ -478,6 +483,7 @@ async def remove_user_from_group( # retry if the group server is currently down. if self.is_mine_id(group_id): + assert isinstance(self.groups_server_handler, GroupsServerHandler) res = await self.groups_server_handler.remove_user_from_group( group_id, user_id, requester_user_id, content ) diff --git a/synapse/server.py b/synapse/server.py index 06946672c1c8..47afff2cd780 100644 --- a/synapse/server.py +++ b/synapse/server.py @@ -609,7 +609,9 @@ def get_groups_local_handler( return GroupsLocalHandler(self) @cache_in_self - def get_groups_server_handler(self): + def get_groups_server_handler( + self, + ) -> Union[GroupsServerWorkerHandler, GroupsServerHandler]: if self.config.worker_app: return GroupsServerWorkerHandler(self) else: From cc2cff9b2e14c1d26d7b06ce8e19851dc0bb6c79 Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Tue, 9 Feb 2021 14:37:20 -0500 Subject: [PATCH 3/7] Add type hints to the room member handler. --- synapse/handlers/register.py | 4 ++-- synapse/handlers/room.py | 5 ++++- synapse/rest/admin/rooms.py | 6 ++++-- synapse/server.py | 4 +++- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/synapse/handlers/register.py b/synapse/handlers/register.py index 49b085269bcb..c7aa99d78e57 100644 --- a/synapse/handlers/register.py +++ b/synapse/handlers/register.py @@ -406,10 +406,10 @@ async def _join_rooms(self, user_id: str) -> None: if RoomAlias.is_valid(r): ( - room_id, + room, remote_room_hosts, ) = await room_member_handler.lookup_room_alias(room_alias) - room_id = room_id.to_string() + room_id = room.to_string() else: raise SynapseError( 400, "%s was not legal room ID or room alias" % (r,) diff --git a/synapse/handlers/room.py b/synapse/handlers/room.py index 1336a23a3ad6..01b6d9a8929a 100644 --- a/synapse/handlers/room.py +++ b/synapse/handlers/room.py @@ -38,6 +38,7 @@ from synapse.api.room_versions import KNOWN_ROOM_VERSIONS, RoomVersion from synapse.events import EventBase from synapse.events.utils import copy_power_levels_contents +from synapse.handlers.room_member import RoomMemberMasterHandler from synapse.rest.admin._base import assert_user_is_admin from synapse.storage.state import StateFilter from synapse.types import ( @@ -1195,7 +1196,9 @@ class RoomShutdownHandler: def __init__(self, hs: "HomeServer"): self.hs = hs - self.room_member_handler = hs.get_room_member_handler() + room_member_handler = hs.get_room_member_handler() + assert isinstance(room_member_handler, RoomMemberMasterHandler) + self.room_member_handler = room_member_handler self._room_creation_handler = hs.get_room_creation_handler() self._replication = hs.get_replication_data_handler() self.event_creation_handler = hs.get_event_creation_handler() diff --git a/synapse/rest/admin/rooms.py b/synapse/rest/admin/rooms.py index 491f9ca09578..db3491be1319 100644 --- a/synapse/rest/admin/rooms.py +++ b/synapse/rest/admin/rooms.py @@ -371,9 +371,11 @@ async def on_POST( except Exception: remote_room_hosts = None elif RoomAlias.is_valid(room_identifier): - handler = self.room_member_handler room_alias = RoomAlias.from_string(room_identifier) - room_id, remote_room_hosts = await handler.lookup_room_alias(room_alias) + room, remote_room_hosts = await self.room_member_handler.lookup_room_alias( + room_alias + ) + room_id = room.to_string() else: raise SynapseError( 400, "%s was not legal room ID or room alias" % (room_identifier,) diff --git a/synapse/server.py b/synapse/server.py index 47afff2cd780..965ad1f42fdb 100644 --- a/synapse/server.py +++ b/synapse/server.py @@ -642,7 +642,9 @@ def get_third_party_event_rules(self) -> ThirdPartyEventRules: return ThirdPartyEventRules(self) @cache_in_self - def get_room_member_handler(self): + def get_room_member_handler( + self, + ) -> Union[RoomMemberWorkerHandler, RoomMemberMasterHandler]: if self.config.worker_app: return RoomMemberWorkerHandler(self) return RoomMemberMasterHandler(self) From 864d14fb23f840336028e5c4a511bbf55f1b4e24 Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Tue, 9 Feb 2021 15:16:46 -0500 Subject: [PATCH 4/7] Add type hints for device handler. --- synapse/handlers/deactivate_account.py | 3 ++ synapse/handlers/devicemessage.py | 5 ++- synapse/handlers/e2e_keys.py | 43 +++++++++++++++++--------- synapse/handlers/federation.py | 5 ++- synapse/handlers/register.py | 5 ++- synapse/handlers/set_password.py | 5 ++- synapse/server.py | 2 +- 7 files changed, 49 insertions(+), 19 deletions(-) diff --git a/synapse/handlers/deactivate_account.py b/synapse/handlers/deactivate_account.py index c4a3b26a8486..8472d65fec48 100644 --- a/synapse/handlers/deactivate_account.py +++ b/synapse/handlers/deactivate_account.py @@ -17,6 +17,7 @@ from typing import TYPE_CHECKING, Optional from synapse.api.errors import SynapseError +from synapse.handlers.device import DeviceHandler from synapse.metrics.background_process_metrics import run_as_background_process from synapse.types import Requester, UserID, create_requester @@ -74,6 +75,8 @@ async def deactivate_account( Returns: True if identity server supports removing threepids, otherwise False. """ + assert isinstance(self._device_handler, DeviceHandler) + # FIXME: Theoretically there is a race here wherein user resets # password using threepid. diff --git a/synapse/handlers/devicemessage.py b/synapse/handlers/devicemessage.py index 0c7737e09d7e..6793a53a4d1e 100644 --- a/synapse/handlers/devicemessage.py +++ b/synapse/handlers/devicemessage.py @@ -17,6 +17,7 @@ from typing import TYPE_CHECKING, Any, Dict from synapse.api.errors import SynapseError +from synapse.handlers.device import DeviceHandler from synapse.logging.context import run_in_background from synapse.logging.opentracing import ( get_active_span_text_map, @@ -69,8 +70,10 @@ def __init__(self, hs: "HomeServer"): # sync. We do all device list resyncing on the master instance, so if # we're on a worker we hit the device resync replication API. if hs.config.worker.worker_app is None: + device_handler = hs.get_device_handler() + assert isinstance(device_handler, DeviceHandler) self._user_device_resync = ( - hs.get_device_handler().device_list_updater.user_device_resync + device_handler.device_list_updater.user_device_resync ) else: self._user_device_resync = ReplicationUserDevicesResyncRestServlet.make_client( diff --git a/synapse/handlers/e2e_keys.py b/synapse/handlers/e2e_keys.py index 8f3a6b35a433..b6bcfb1f1075 100644 --- a/synapse/handlers/e2e_keys.py +++ b/synapse/handlers/e2e_keys.py @@ -27,6 +27,7 @@ from twisted.internet import defer from synapse.api.errors import CodeMessageException, Codes, NotFoundError, SynapseError +from synapse.handlers.device import DeviceHandler from synapse.logging.context import make_deferred_yieldable, run_in_background from synapse.logging.opentracing import log_kv, set_tag, tag_args, trace from synapse.replication.http.devices import ReplicationUserDevicesResyncRestServlet @@ -51,24 +52,26 @@ class E2eKeysHandler: def __init__(self, hs: "HomeServer"): self.store = hs.get_datastore() self.federation = hs.get_federation_client() - self.device_handler = hs.get_device_handler() self.is_mine = hs.is_mine self.clock = hs.get_clock() - self._edu_updater = SigningKeyEduUpdater(hs, self) - federation_registry = hs.get_federation_registry() - self._is_master = hs.config.worker_app is None - if not self._is_master: + self.device_handler = None # type: Optional[DeviceHandler] + if hs.config.worker_app is not None: self._user_device_resync_client = ReplicationUserDevicesResyncRestServlet.make_client( hs ) else: + device_handler = hs.get_device_handler() + assert isinstance(device_handler, DeviceHandler) + self.device_handler = device_handler + # Only register this edu handler on master as it requires writing # device updates to the db # # FIXME: switch to m.signing_key_update when MSC1756 is merged into the spec + self._edu_updater = SigningKeyEduUpdater(hs, device_handler) federation_registry.register_edu_handler( "org.matrix.signing_key_update", self._edu_updater.incoming_signing_key_update, @@ -226,16 +229,23 @@ async def do_remote_query(destination): # probably be tracking their device lists. However, we haven't # done an initial sync on the device list so we do it now. try: - if self._is_master: - user_devices = await self.device_handler.device_list_updater.user_device_resync( + if self.device_handler: + user_device_resync = await self.device_handler.device_list_updater.user_device_resync( user_id ) else: - user_devices = await self._user_device_resync_client( + user_device_resync = await self._user_device_resync_client( user_id=user_id ) - user_devices = user_devices["devices"] + if user_device_resync is None: + failures[destination] = { + "status": 503, + "message": "Unable to resync devices", + } + continue + + user_devices = user_device_resync["devices"] user_results = results.setdefault(user_id, {}) for device in user_devices: user_results[device["device_id"]] = device["keys"] @@ -486,6 +496,7 @@ async def claim_client_keys(destination): async def upload_keys_for_user( self, user_id: str, device_id: str, keys: JsonDict ) -> JsonDict: + assert self.device_handler time_now = self.clock.time_msec() @@ -611,6 +622,7 @@ async def upload_signing_keys_for_user( user_id: the user uploading the keys keys: the signing keys """ + assert self.device_handler # if a master key is uploaded, then check it. Otherwise, load the # stored master key, to check signatures on other keys @@ -702,6 +714,8 @@ async def upload_signatures_for_device_keys( Raises: SynapseError: if the signatures dict is not valid. """ + assert self.device_handler + failures = {} # signatures to be stored. Each item will be a SignatureListItem @@ -1080,6 +1094,8 @@ async def _retrieve_cross_signing_keys_for_remote_user( A tuple of the retrieved key content, the key's ID and the matching VerifyKey. If the key cannot be retrieved, all values in the tuple will instead be None. """ + assert self.device_handler + try: remote_result = await self.federation.query_user_devices( user.domain, user.to_string() @@ -1281,11 +1297,11 @@ class SignatureListItem: class SigningKeyEduUpdater: """Handles incoming signing key updates from federation and updates the DB""" - def __init__(self, hs: "HomeServer", e2e_keys_handler: E2eKeysHandler): + def __init__(self, hs: "HomeServer", device_handler: DeviceHandler): self.store = hs.get_datastore() self.federation = hs.get_federation_client() self.clock = hs.get_clock() - self.e2e_keys_handler = e2e_keys_handler + self.device_handler = device_handler self._remote_edu_linearizer = Linearizer(name="remote_signing_key") @@ -1341,8 +1357,7 @@ async def _handle_signing_key_updates(self, user_id: str) -> None: user_id: the user whose updates we are processing """ - device_handler = self.e2e_keys_handler.device_handler - device_list_updater = device_handler.device_list_updater + device_list_updater = self.device_handler.device_list_updater with (await self._remote_edu_linearizer.queue(user_id)): pending_updates = self._pending_updates.pop(user_id, []) @@ -1360,4 +1375,4 @@ async def _handle_signing_key_updates(self, user_id: str) -> None: ) device_ids = device_ids + new_device_ids - await device_handler.notify_device_update(user_id, device_ids) + await self.device_handler.notify_device_update(user_id, device_ids) diff --git a/synapse/handlers/federation.py b/synapse/handlers/federation.py index eddc7582d0c5..dd6f4246c022 100644 --- a/synapse/handlers/federation.py +++ b/synapse/handlers/federation.py @@ -55,6 +55,7 @@ from synapse.events.snapshot import EventContext from synapse.events.validator import EventValidator from synapse.handlers._base import BaseHandler +from synapse.handlers.device import DeviceHandler from synapse.http.servlet import assert_params_in_dict from synapse.logging.context import ( make_deferred_yieldable, @@ -157,7 +158,9 @@ def __init__(self, hs: "HomeServer"): hs ) else: - self._device_list_updater = hs.get_device_handler().device_list_updater + device_handler = hs.get_device_handler() + assert isinstance(device_handler, DeviceHandler) + self._device_list_updater = device_handler.device_list_updater self._maybe_store_room_on_outlier_membership = ( self.store.maybe_store_room_on_outlier_membership ) diff --git a/synapse/handlers/register.py b/synapse/handlers/register.py index c7aa99d78e57..9b8e29dbc593 100644 --- a/synapse/handlers/register.py +++ b/synapse/handlers/register.py @@ -23,6 +23,7 @@ from synapse.api.errors import AuthError, Codes, ConsentNotGivenError, SynapseError from synapse.appservice import ApplicationService from synapse.config.server import is_threepid_reserved +from synapse.handlers.device import DeviceHandler from synapse.http.servlet import assert_params_in_dict from synapse.replication.http.login import RegisterDeviceReplicationServlet from synapse.replication.http.register import ( @@ -66,7 +67,9 @@ def __init__(self, hs: "HomeServer"): hs ) else: - self.device_handler = hs.get_device_handler() + device_handler = hs.get_device_handler() + assert isinstance(device_handler, DeviceHandler) + self.device_handler = device_handler self.pusher_pool = hs.get_pusherpool() self.session_lifetime = hs.config.session_lifetime diff --git a/synapse/handlers/set_password.py b/synapse/handlers/set_password.py index 84af2dde7ea5..483fa83cf109 100644 --- a/synapse/handlers/set_password.py +++ b/synapse/handlers/set_password.py @@ -16,6 +16,7 @@ from typing import TYPE_CHECKING, Optional from synapse.api.errors import Codes, StoreError, SynapseError +from synapse.handlers.device import DeviceHandler from synapse.types import Requester from ._base import BaseHandler @@ -32,7 +33,9 @@ class SetPasswordHandler(BaseHandler): def __init__(self, hs: "HomeServer"): super().__init__(hs) self._auth_handler = hs.get_auth_handler() - self._device_handler = hs.get_device_handler() + device_handler = hs.get_device_handler() + assert isinstance(device_handler, DeviceHandler) + self._device_handler = device_handler async def set_password( self, diff --git a/synapse/server.py b/synapse/server.py index 965ad1f42fdb..bd2a4546d368 100644 --- a/synapse/server.py +++ b/synapse/server.py @@ -452,7 +452,7 @@ def get_macaroon_generator(self) -> MacaroonGenerator: return MacaroonGenerator(self) @cache_in_self - def get_device_handler(self): + def get_device_handler(self) -> Union[DeviceWorkerHandler, DeviceHandler]: if self.config.worker_app: return DeviceWorkerHandler(self) else: From 6edbffb3dda6830d5bf559b2855b1bccdc95528a Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Tue, 9 Feb 2021 15:18:26 -0500 Subject: [PATCH 5/7] Additional type hints for E2E keys handler. --- synapse/handlers/e2e_keys.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/synapse/handlers/e2e_keys.py b/synapse/handlers/e2e_keys.py index b6bcfb1f1075..1e6bfbde149b 100644 --- a/synapse/handlers/e2e_keys.py +++ b/synapse/handlers/e2e_keys.py @@ -197,7 +197,7 @@ async def query_devices( # Now fetch any devices that we don't have in our cache @trace - async def do_remote_query(destination): + async def do_remote_query(destination: str) -> None: """This is called when we are querying the device list of a user on a remote homeserver and their device list is not in the device list cache. If we share a room with this user and we're not querying for @@ -450,7 +450,7 @@ async def claim_one_time_keys( } @trace - async def claim_client_keys(destination): + async def claim_client_keys(destination: str) -> None: set_tag("destination", destination) device_keys = remote_queries[destination] try: From b4311a6c0588189a86687193bfb48f908c218f5d Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Wed, 10 Feb 2021 11:09:57 -0500 Subject: [PATCH 6/7] Newsfragment --- changelog.d/9374.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/9374.misc diff --git a/changelog.d/9374.misc b/changelog.d/9374.misc new file mode 100644 index 000000000000..5aa5c113bd78 --- /dev/null +++ b/changelog.d/9374.misc @@ -0,0 +1 @@ +Add type hints to various parts of the code base. From 3101a304fc2093c2eb23e38ce2b11a853a2e0c9b Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Thu, 11 Feb 2021 11:19:06 -0500 Subject: [PATCH 7/7] Do not raise asseritions during initialization. --- synapse/handlers/room.py | 5 ++--- synapse/handlers/set_password.py | 6 +++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/synapse/handlers/room.py b/synapse/handlers/room.py index 01b6d9a8929a..0bc302fccd5f 100644 --- a/synapse/handlers/room.py +++ b/synapse/handlers/room.py @@ -1196,9 +1196,7 @@ class RoomShutdownHandler: def __init__(self, hs: "HomeServer"): self.hs = hs - room_member_handler = hs.get_room_member_handler() - assert isinstance(room_member_handler, RoomMemberMasterHandler) - self.room_member_handler = room_member_handler + self.room_member_handler = hs.get_room_member_handler() self._room_creation_handler = hs.get_room_creation_handler() self._replication = hs.get_replication_data_handler() self.event_creation_handler = hs.get_event_creation_handler() @@ -1259,6 +1257,7 @@ async def shutdown_room( migrated from the old room to the new. new_room_id: A string representing the room ID of the new room. """ + assert isinstance(self.room_member_handler, RoomMemberMasterHandler) if not new_room_name: new_room_name = self.DEFAULT_ROOM_NAME diff --git a/synapse/handlers/set_password.py b/synapse/handlers/set_password.py index 483fa83cf109..54a4eef1f4ae 100644 --- a/synapse/handlers/set_password.py +++ b/synapse/handlers/set_password.py @@ -33,9 +33,7 @@ class SetPasswordHandler(BaseHandler): def __init__(self, hs: "HomeServer"): super().__init__(hs) self._auth_handler = hs.get_auth_handler() - device_handler = hs.get_device_handler() - assert isinstance(device_handler, DeviceHandler) - self._device_handler = device_handler + self._device_handler = hs.get_device_handler() async def set_password( self, @@ -44,6 +42,8 @@ async def set_password( logout_devices: bool, requester: Optional[Requester] = None, ) -> None: + assert isinstance(self._device_handler, DeviceHandler) + if not self.hs.config.password_localdb_enabled: raise SynapseError(403, "Password change disabled", errcode=Codes.FORBIDDEN)