From ad1dedf7b451e515ae0aef985c31685ab487947b Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Tue, 31 Aug 2021 13:38:09 -0400 Subject: [PATCH 1/3] Ignore rooms with unknown room versions in the spaces summary. --- synapse/handlers/room_summary.py | 14 ++++++++++++-- tests/handlers/test_room_summary.py | 25 +++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/synapse/handlers/room_summary.py b/synapse/handlers/room_summary.py index 906985c754d9..2d72e0736ff3 100644 --- a/synapse/handlers/room_summary.py +++ b/synapse/handlers/room_summary.py @@ -28,7 +28,14 @@ Membership, RoomTypes, ) -from synapse.api.errors import AuthError, Codes, NotFoundError, StoreError, SynapseError +from synapse.api.errors import ( + AuthError, + Codes, + NotFoundError, + StoreError, + SynapseError, + UnsupportedRoomVersionError, +) from synapse.events import EventBase from synapse.events.utils import format_event_for_client_v2 from synapse.types import JsonDict @@ -814,7 +821,10 @@ async def _is_local_room_accessible( logger.info("room %s is unknown, omitting from summary", room_id) return False - room_version = await self._store.get_room_version(room_id) + try: + room_version = await self._store.get_room_version(room_id) + except UnsupportedRoomVersionError: + return False # Include the room if it has join rules of public or knock. join_rules_event_id = state_ids.get((EventTypes.JoinRules, "")) diff --git a/tests/handlers/test_room_summary.py b/tests/handlers/test_room_summary.py index ac800afa7d3e..412b62ad9253 100644 --- a/tests/handlers/test_room_summary.py +++ b/tests/handlers/test_room_summary.py @@ -573,6 +573,31 @@ def test_max_depth(self): ] self._assert_hierarchy(result, expected) + def test_unknown_room_version(self): + """ + If an room with an unknown room version is encountered it should not cause + the entire summary to skip. + """ + # Poke the database and update the room version to an unknown one. + self.get_success( + self.hs.get_datastores().main.db_pool.simple_update( + "rooms", + keyvalues={"room_id": self.room}, + updatevalues={"room_version": "unknown-room-version"}, + desc="updated-room-version", + ) + ) + + result = self.get_success(self.handler.get_space_summary(self.user, self.space)) + # The result should have only the space, along with a link from space -> room. + expected = [(self.space, [self.room])] + self._assert_rooms(result, expected) + + result = self.get_success( + self.handler.get_room_hierarchy(self.user, self.space) + ) + self._assert_hierarchy(result, expected) + def test_fed_complex(self): """ Return data over federation and ensure that it is handled properly. From 8987bd414018fc81a4d8c6b1836eae28999f50c5 Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Tue, 31 Aug 2021 13:45:51 -0400 Subject: [PATCH 2/3] Newsfragment --- changelog.d/10727.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/10727.misc diff --git a/changelog.d/10727.misc b/changelog.d/10727.misc new file mode 100644 index 000000000000..63fe6e5c7dea --- /dev/null +++ b/changelog.d/10727.misc @@ -0,0 +1 @@ +Do not include rooms with unknown room versions in the spaces summary results. From 5e523d021bf96063b7a7e43be484f60f8e3da576 Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Wed, 1 Sep 2021 12:34:47 -0400 Subject: [PATCH 3/3] Add clarifying comment. --- synapse/handlers/room_summary.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/synapse/handlers/room_summary.py b/synapse/handlers/room_summary.py index 2d72e0736ff3..047deb39e5bf 100644 --- a/synapse/handlers/room_summary.py +++ b/synapse/handlers/room_summary.py @@ -824,6 +824,8 @@ async def _is_local_room_accessible( try: room_version = await self._store.get_room_version(room_id) except UnsupportedRoomVersionError: + # If a room with an unsupported room version is encountered, ignore + # it to avoid breaking the entire summary response. return False # Include the room if it has join rules of public or knock.