@@ -227,7 +227,7 @@ async def claim_client_keys(
227227 )
228228
229229 async def backfill (
230- self , dest : str , room_id : str , limit : int , extremities : Iterable [str ]
230+ self , dest : str , room_id : str , limit : int , extremities : Collection [str ]
231231 ) -> Optional [List [EventBase ]]:
232232 """Requests some more historic PDUs for the given room from the
233233 given destination server.
@@ -237,6 +237,8 @@ async def backfill(
237237 room_id: The room_id to backfill.
238238 limit: The maximum number of events to return.
239239 extremities: our current backwards extremities, to backfill from
240+ Must be a Collection that is falsy when empty.
241+ (Iterable is not enough here!)
240242 """
241243 logger .debug ("backfill extrem=%s" , extremities )
242244
@@ -250,11 +252,22 @@ async def backfill(
250252
251253 logger .debug ("backfill transaction_data=%r" , transaction_data )
252254
255+ if not isinstance (transaction_data , dict ):
256+ # TODO we probably want an exception type specific to federation
257+ # client validation.
258+ raise TypeError ("Backfill transaction_data is not a dict." )
259+
260+ transaction_data_pdus = transaction_data .get ("pdus" )
261+ if not isinstance (transaction_data_pdus , list ):
262+ # TODO we probably want an exception type specific to federation
263+ # client validation.
264+ raise TypeError ("transaction_data.pdus is not a list." )
265+
253266 room_version = await self .store .get_room_version (room_id )
254267
255268 pdus = [
256269 event_from_pdu_json (p , room_version , outlier = False )
257- for p in transaction_data [ "pdus" ]
270+ for p in transaction_data_pdus
258271 ]
259272
260273 # Check signatures and hash of pdus, removing any from the list that fail checks
0 commit comments