Add an upstream patch to fix a regression in 1.27:
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType." related to the user directory
Andrej Shadura
3 years ago
0 | From 436a9899226f8097064d3c6bd4eff533c9d8043f Mon Sep 17 00:00:00 2001 | |
1 | From: Patrick Cloke <patrickc@matrix.org> | |
2 | Date: Wed, 17 Feb 2021 13:00:58 -0500 | |
3 | Subject: [PATCH] Add back the guard against the user directory stream position | |
4 | not existing. | |
5 | ||
6 | --- | |
7 | changelog.d/9428.bugfix | 1 + | |
8 | synapse/handlers/user_directory.py | 4 ++++ | |
9 | synapse/storage/databases/main/user_directory.py | 8 +++++++- | |
10 | 3 files changed, 12 insertions(+), 1 deletion(-) | |
11 | create mode 100644 changelog.d/9428.bugfix | |
12 | ||
13 | diff --git a/changelog.d/9428.bugfix b/changelog.d/9428.bugfix | |
14 | new file mode 100644 | |
15 | index 00000000000..132e35440a3 | |
16 | --- /dev/null | |
17 | +++ b/changelog.d/9428.bugfix | |
18 | @@ -0,0 +1 @@ | |
19 | +Fix a bug introduced in v1.27.0: "TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType." related to the user directory. | |
20 | diff --git a/synapse/handlers/user_directory.py b/synapse/handlers/user_directory.py | |
21 | index 3dfb0a26c2a..1a8340000a5 100644 | |
22 | --- a/synapse/handlers/user_directory.py | |
23 | +++ b/synapse/handlers/user_directory.py | |
24 | @@ -143,6 +143,10 @@ async def _unsafe_process(self) -> None: | |
25 | if self.pos is None: | |
26 | self.pos = await self.store.get_user_directory_stream_pos() | |
27 | ||
28 | + # If still None then the initial background update hasn't happened yet. | |
29 | + if self.pos is None: | |
30 | + return None | |
31 | + | |
32 | # Loop round handling deltas until we're up to date | |
33 | while True: | |
34 | with Measure(self.clock, "user_dir_delta"): | |
35 | diff --git a/synapse/storage/databases/main/user_directory.py b/synapse/storage/databases/main/user_directory.py | |
36 | index 3a1fe3ed52b..63f88eac51b 100644 | |
37 | --- a/synapse/storage/databases/main/user_directory.py | |
38 | +++ b/synapse/storage/databases/main/user_directory.py | |
39 | @@ -707,7 +707,13 @@ def _get_shared_rooms_for_users_txn(txn): | |
40 | ||
41 | return {row["room_id"] for row in rows} | |
42 | ||
43 | - async def get_user_directory_stream_pos(self) -> int: | |
44 | + async def get_user_directory_stream_pos(self) -> Optional[int]: | |
45 | + """ | |
46 | + Get the stream ID of the user directory stream. | |
47 | + | |
48 | + Returns: | |
49 | + The stream token or None if the initial background update hasn't happened yet. | |
50 | + """ | |
51 | return await self.db_pool.simple_select_one_onecol( | |
52 | table="user_directory_stream_pos", | |
53 | keyvalues={}, |