-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add missing type hints to replication.http. #11856
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Add missing type hints to replication code. |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -13,13 +13,18 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # limitations under the License. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import logging | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from typing import TYPE_CHECKING | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from typing import TYPE_CHECKING, List, Tuple | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from synapse.api.room_versions import KNOWN_ROOM_VERSIONS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from synapse.events import make_event_from_dict | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from twisted.web.server import Request | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from synapse.api.room_versions import KNOWN_ROOM_VERSIONS, RoomVersion | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from synapse.events import EventBase, make_event_from_dict | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from synapse.events.snapshot import EventContext | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from synapse.http.server import HttpServer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from synapse.http.servlet import parse_json_object_from_request | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from synapse.replication.http._base import ReplicationEndpoint | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from synapse.storage.databases.main import DataStore | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from synapse.types import JsonDict | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from synapse.util.metrics import Measure | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if TYPE_CHECKING: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -69,14 +74,18 @@ def __init__(self, hs: "HomeServer"): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self.federation_event_handler = hs.get_federation_event_handler() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @staticmethod | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async def _serialize_payload(store, room_id, event_and_contexts, backfilled): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async def _serialize_payload( # type: ignore[override] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| store: DataStore, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| room_id: str, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| event_and_contexts: List[Tuple[EventBase, EventContext]], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| backfilled: bool, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) -> JsonDict: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Args: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| store | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| room_id (str) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| event_and_contexts (list[tuple[FrozenEvent, EventContext]]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| backfilled (bool): Whether or not the events are the result of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| backfilling | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| room_id | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| event_and_contexts | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| backfilled: Whether or not the events are the result of backfilling | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| event_payloads = [] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for event, context in event_and_contexts: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -102,7 +111,7 @@ async def _serialize_payload(store, room_id, event_and_contexts, backfilled): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return payload | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async def _handle_request(self, request): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async def _handle_request(self, request: Request) -> Tuple[int, JsonDict]: # type: ignore[override] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| with Measure(self.clock, "repl_fed_send_events_parse"): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| content = parse_json_object_from_request(request) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -163,10 +172,14 @@ def __init__(self, hs: "HomeServer"): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self.registry = hs.get_federation_registry() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @staticmethod | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async def _serialize_payload(edu_type, origin, content): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async def _serialize_payload( # type: ignore[override] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| edu_type: str, origin: str, content: JsonDict | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) -> JsonDict: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return {"origin": origin, "content": content} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async def _handle_request(self, request, edu_type): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async def _handle_request( # type: ignore[override] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self, request: Request, edu_type: str | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) -> Tuple[int, JsonDict]: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| with Measure(self.clock, "repl_fed_send_edu_parse"): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| content = parse_json_object_from_request(request) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -175,9 +188,9 @@ async def _handle_request(self, request, edu_type): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| logger.info("Got %r edu from %s", edu_type, origin) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| result = await self.registry.on_edu(edu_type, origin, edu_content) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await self.registry.on_edu(edu_type, origin, edu_content) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return 200, result | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return 200, {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class ReplicationGetQueryRestServlet(ReplicationEndpoint): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -206,15 +219,17 @@ def __init__(self, hs: "HomeServer"): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self.registry = hs.get_federation_registry() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @staticmethod | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async def _serialize_payload(query_type, args): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async def _serialize_payload(query_type: str, args: JsonDict) -> JsonDict: # type: ignore[override] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Args: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| query_type (str) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| args (dict): The arguments received for the given query type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| query_type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| args: The arguments received for the given query type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return {"args": args} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async def _handle_request(self, request, query_type): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async def _handle_request( # type: ignore[override] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self, request: Request, query_type: str | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) -> Tuple[int, JsonDict]: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| with Measure(self.clock, "repl_fed_query_parse"): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| content = parse_json_object_from_request(request) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -248,14 +263,16 @@ def __init__(self, hs: "HomeServer"): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self.store = hs.get_datastore() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @staticmethod | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async def _serialize_payload(room_id, args): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The only caller of this seems to only pass a synapse/synapse/handlers/federation.py Lines 1379 to 1389 in 251b556
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Anything in sentry for this? Maybe it's just never called?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems to be called via
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there is a clue here: synapse/synapse/handlers/federation.py Lines 452 to 474 in 251b556
I couldn't see any other call site of |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async def _serialize_payload(room_id: str) -> JsonDict: # type: ignore[override] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Args: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| room_id (str) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| room_id | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async def _handle_request(self, request, room_id): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async def _handle_request( # type: ignore[override] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self, request: Request, room_id: str | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) -> Tuple[int, JsonDict]: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await self.store.clean_room_for_join(room_id) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return 200, {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -283,17 +300,19 @@ def __init__(self, hs: "HomeServer"): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self.store = hs.get_datastore() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @staticmethod | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async def _serialize_payload(room_id, room_version): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async def _serialize_payload(room_id: str, room_version: RoomVersion) -> JsonDict: # type: ignore[override] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return {"room_version": room_version.identifier} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async def _handle_request(self, request, room_id): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async def _handle_request( # type: ignore[override] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self, request: Request, room_id: str | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) -> Tuple[int, JsonDict]: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| content = parse_json_object_from_request(request) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| room_version = KNOWN_ROOM_VERSIONS[content["room_version"]] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await self.store.maybe_store_room_on_outlier_membership(room_id, room_version) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return 200, {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def register_servlets(hs: "HomeServer", http_server): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def register_servlets(hs: "HomeServer", http_server: HttpServer) -> None: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ReplicationFederationSendEventsRestServlet(hs).register(http_server) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ReplicationFederationSendEduRestServlet(hs).register(http_server) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ReplicationGetQueryRestServlet(hs).register(http_server) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.