diff --git a/synapse/handlers/room.py b/synapse/handlers/room.py index 97239b1b491..41b00a5cf7b 100644 --- a/synapse/handlers/room.py +++ b/synapse/handlers/room.py @@ -1744,7 +1744,7 @@ async def get_new_events( # We know stream_ordering must be not None here, as its been # persisted, but mypy doesn't know that - events.sort(key=lambda e: e.internal_metadata.stream_ordering or 0) + events.sort(key=lambda e: cast(int, e.internal_metadata.stream_ordering)) if limit: events[:] = events[:limit]