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

Fix admin List Room API return type on sqlite #13509

Merged
merged 3 commits into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/13509.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a bug introduced in Synapse 1.13 where the [List Rooms admin API](https://matrix-org.github.io/synapse/develop/admin_api/rooms.html#list-room-api) would return integers instead of booleans for the `federatable` and `public` fields when using a Sqlite database.
6 changes: 4 additions & 2 deletions synapse/storage/databases/main/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,8 +641,10 @@ def _get_rooms_paginate_txn(
"version": room[5],
"creator": room[6],
"encryption": room[7],
"federatable": room[8],
"public": room[9],
# room_stats_state.federatable is an integer on sqlite.
"federatable": bool(room[8]),
# rooms.is_public is an integer on sqlite.
"public": bool(room[9]),
"join_rules": room[10],
"guest_access": room[11],
"history_visibility": room[12],
Expand Down
19 changes: 14 additions & 5 deletions tests/rest/admin/test_room.py
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,9 @@ def test_list_rooms(self) -> None:
room_ids = []
for _ in range(total_rooms):
room_id = self.helper.create_room_as(
self.admin_user, tok=self.admin_user_tok
self.admin_user,
tok=self.admin_user_tok,
is_public=True,
)
room_ids.append(room_id)

Expand Down Expand Up @@ -1119,8 +1121,8 @@ def test_list_rooms(self) -> None:
self.assertIn("version", r)
self.assertIn("creator", r)
self.assertIn("encryption", r)
self.assertIn("federatable", r)
self.assertIn("public", r)
self.assertIs(r["federatable"], True)
self.assertIs(r["public"], True)
self.assertIn("join_rules", r)
self.assertIn("guest_access", r)
self.assertIn("history_visibility", r)
Expand Down Expand Up @@ -1587,8 +1589,12 @@ def test_search_term_non_ascii(self) -> None:
def test_single_room(self) -> None:
"""Test that a single room can be requested correctly"""
# Create two test rooms
room_id_1 = self.helper.create_room_as(self.admin_user, tok=self.admin_user_tok)
room_id_2 = self.helper.create_room_as(self.admin_user, tok=self.admin_user_tok)
room_id_1 = self.helper.create_room_as(
self.admin_user, tok=self.admin_user_tok, is_public=True
)
room_id_2 = self.helper.create_room_as(
self.admin_user, tok=self.admin_user_tok, is_public=False
)

room_name_1 = "something"
room_name_2 = "else"
Expand Down Expand Up @@ -1634,7 +1640,10 @@ def test_single_room(self) -> None:
self.assertIn("state_events", channel.json_body)
self.assertIn("room_type", channel.json_body)
self.assertIn("forgotten", channel.json_body)

self.assertEqual(room_id_1, channel.json_body["room_id"])
self.assertIs(True, channel.json_body["federatable"])
self.assertIs(True, channel.json_body["public"])

def test_single_room_devices(self) -> None:
"""Test that `joined_local_devices` can be requested correctly"""
Expand Down