Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit c586d68

Browse files
authored
Ignore rooms with unknown room versions in the spaces summary. (#10727)
This avoids breaking the entire endpoint if a room with an unsupported room version is encountered.
1 parent 6258730 commit c586d68

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

changelog.d/10727.misc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Do not include rooms with unknown room versions in the spaces summary results.

synapse/handlers/room_summary.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,14 @@
2828
Membership,
2929
RoomTypes,
3030
)
31-
from synapse.api.errors import AuthError, Codes, NotFoundError, StoreError, SynapseError
31+
from synapse.api.errors import (
32+
AuthError,
33+
Codes,
34+
NotFoundError,
35+
StoreError,
36+
SynapseError,
37+
UnsupportedRoomVersionError,
38+
)
3239
from synapse.events import EventBase
3340
from synapse.events.utils import format_event_for_client_v2
3441
from synapse.types import JsonDict
@@ -814,7 +821,12 @@ async def _is_local_room_accessible(
814821
logger.info("room %s is unknown, omitting from summary", room_id)
815822
return False
816823

817-
room_version = await self._store.get_room_version(room_id)
824+
try:
825+
room_version = await self._store.get_room_version(room_id)
826+
except UnsupportedRoomVersionError:
827+
# If a room with an unsupported room version is encountered, ignore
828+
# it to avoid breaking the entire summary response.
829+
return False
818830

819831
# Include the room if it has join rules of public or knock.
820832
join_rules_event_id = state_ids.get((EventTypes.JoinRules, ""))

tests/handlers/test_room_summary.py

+25
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,31 @@ def test_max_depth(self):
581581
]
582582
self._assert_hierarchy(result, expected)
583583

584+
def test_unknown_room_version(self):
585+
"""
586+
If an room with an unknown room version is encountered it should not cause
587+
the entire summary to skip.
588+
"""
589+
# Poke the database and update the room version to an unknown one.
590+
self.get_success(
591+
self.hs.get_datastores().main.db_pool.simple_update(
592+
"rooms",
593+
keyvalues={"room_id": self.room},
594+
updatevalues={"room_version": "unknown-room-version"},
595+
desc="updated-room-version",
596+
)
597+
)
598+
599+
result = self.get_success(self.handler.get_space_summary(self.user, self.space))
600+
# The result should have only the space, along with a link from space -> room.
601+
expected = [(self.space, [self.room])]
602+
self._assert_rooms(result, expected)
603+
604+
result = self.get_success(
605+
self.handler.get_room_hierarchy(self.user, self.space)
606+
)
607+
self._assert_hierarchy(result, expected)
608+
584609
def test_fed_complex(self):
585610
"""
586611
Return data over federation and ensure that it is handled properly.

0 commit comments

Comments
 (0)