diff --git a/changelog.d/9428.bugfix b/changelog.d/9428.bugfix new file mode 100644 index 0000000000000000000000000000000000000000..132e35440a3e4e4c8134d359627e83d8b9e52fb6 --- /dev/null +++ b/changelog.d/9428.bugfix @@ -0,0 +1 @@ +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. diff --git a/synapse/handlers/user_directory.py b/synapse/handlers/user_directory.py index 3dfb0a26c2a4ced41a038e79b5c15cce76b15028..1a8340000a590636bfa08d23910d699ea43ab5c5 100644 --- a/synapse/handlers/user_directory.py +++ b/synapse/handlers/user_directory.py @@ -143,6 +143,10 @@ class UserDirectoryHandler(StateDeltasHandler): if self.pos is None: self.pos = await self.store.get_user_directory_stream_pos() + # If still None then the initial background update hasn't happened yet. + if self.pos is None: + return None + # Loop round handling deltas until we're up to date while True: with Measure(self.clock, "user_dir_delta"): diff --git a/synapse/storage/databases/main/user_directory.py b/synapse/storage/databases/main/user_directory.py index 3a1fe3ed52b1f3e3f66dd3fc363169b23ba7695c..63f88eac51bdfd121e8c85264e446d7020d00160 100644 --- a/synapse/storage/databases/main/user_directory.py +++ b/synapse/storage/databases/main/user_directory.py @@ -707,7 +707,13 @@ class UserDirectoryStore(UserDirectoryBackgroundUpdateStore): return {row["room_id"] for row in rows} - async def get_user_directory_stream_pos(self) -> int: + async def get_user_directory_stream_pos(self) -> Optional[int]: + """ + Get the stream ID of the user directory stream. + + Returns: + The stream token or None if the initial background update hasn't happened yet. + """ return await self.db_pool.simple_select_one_onecol( table="user_directory_stream_pos", keyvalues={},