diff --git a/synapse/handlers/sync.py b/synapse/handlers/sync.py index 3f80bc83ea3f..7801aeb28802 100644 --- a/synapse/handlers/sync.py +++ b/synapse/handlers/sync.py @@ -1335,7 +1335,7 @@ async def _generate_sync_entry_for_to_device( if sync_result_builder.since_token is not None: since_stream_id = int(sync_result_builder.since_token.to_device_key) - if since_stream_id != int(now_token.to_device_key): + if device_id is not None and since_stream_id != int(now_token.to_device_key): messages, stream_id = await self.store.get_messages_for_device( user_id, device_id, since_stream_id, now_token.to_device_key )