diff --git a/synapse/handlers/sync.py b/synapse/handlers/sync.py index 7e2a892b63ae..dcb720dcf7b7 100644 --- a/synapse/handlers/sync.py +++ b/synapse/handlers/sync.py @@ -90,7 +90,7 @@ class SyncConfig: filter_collection: FilterCollection is_guest: bool request_key: SyncRequestKey - device_id: Optional[str] + device_id: str @attr.s(slots=True, frozen=True, auto_attribs=True) @@ -288,7 +288,7 @@ def __init__(self, hs: "HomeServer"): # ExpiringCache((User, Device)) -> LruCache(user_id => event_id) self.lazy_loaded_members_cache: ExpiringCache[ - Tuple[str, Optional[str]], LruCache[str, str] + Tuple[str, str], LruCache[str, str] ] = ExpiringCache( "lazy_loaded_members_cache", self.clock, @@ -833,7 +833,7 @@ async def compute_summary( return summary def get_lazy_loaded_members_cache( - self, cache_key: Tuple[str, Optional[str]] + self, cache_key: Tuple[str, str] ) -> LruCache[str, str]: cache: Optional[LruCache[str, str]] = self.lazy_loaded_members_cache.get( cache_key diff --git a/synapse/rest/client/sync.py b/synapse/rest/client/sync.py index d20ae1421e19..5fedc1d13375 100644 --- a/synapse/rest/client/sync.py +++ b/synapse/rest/client/sync.py @@ -125,6 +125,9 @@ async def on_GET(self, request: SynapseRequest) -> Tuple[int, JsonDict]: user = requester.user device_id = requester.device_id + # We must have a device ID, as this request is authenticated. + assert device_id + timeout = parse_integer(request, "timeout", default=0) since = parse_string(request, "since") set_presence = parse_string( diff --git a/synapse/storage/databases/main/deviceinbox.py b/synapse/storage/databases/main/deviceinbox.py index 4eca97189bef..d4a57260617b 100644 --- a/synapse/storage/databases/main/deviceinbox.py +++ b/synapse/storage/databases/main/deviceinbox.py @@ -139,7 +139,7 @@ def get_to_device_stream_token(self): async def get_new_messages_for_device( self, user_id: str, - device_id: Optional[str], + device_id: str, last_stream_id: int, current_stream_id: int, limit: int = 100, @@ -197,7 +197,7 @@ def get_new_messages_for_device_txn(txn): @trace async def delete_messages_for_device( - self, user_id: str, device_id: Optional[str], up_to_stream_id: int + self, user_id: str, device_id: str, up_to_stream_id: int ) -> int: """ Args: diff --git a/tests/handlers/test_sync.py b/tests/handlers/test_sync.py index 07a760e91aed..95026e82c42e 100644 --- a/tests/handlers/test_sync.py +++ b/tests/handlers/test_sync.py @@ -282,7 +282,7 @@ def test_ban_wins_race_with_join(self): def generate_sync_config( - user_id: str, device_id: Optional[str] = "device_id" + user_id: str, device_id: str = "device_id" ) -> SyncConfig: """Generate a sync config (with a unique request key).""" global _request_key