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

Add back the guard against the user directory stream position being unset #9428

Merged
merged 1 commit into from
Feb 18, 2021
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/9428.bugfix
Original file line number Diff line number Diff line change
@@ -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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this have a user visible effect?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so since the user directory wouldn't be ready to be updated anyway?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair :)

4 changes: 4 additions & 0 deletions synapse/handlers/user_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ async def _unsafe_process(self) -> None:
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"):
Expand Down
8 changes: 7 additions & 1 deletion synapse/storage/databases/main/user_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,13 @@ def _get_shared_rooms_for_users_txn(txn):

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={},
Expand Down