This repository was archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Fix /messages
throwing a 500 when querying for non-existent room
#12683
Merged
MadLittleMods
merged 3 commits into
develop
from
madlittlemods/12678-403-when-/messages-with-does-not-exist-room-id
May 11, 2022
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix a bug introduced in Synapse 1.57.0 where `/messages` would throw a 500 error when querying for a non-existent room. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -785,22 +785,14 @@ async def get_last_event_in_room_before_stream_ordering( | |
return None | ||
|
||
async def get_current_room_stream_token_for_room_id( | ||
self, room_id: Optional[str] = None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've checked the usages. We never have to worry about a case where the
|
||
self, room_id: str | ||
) -> RoomStreamToken: | ||
"""Returns the current position of the rooms stream. | ||
|
||
By default, it returns a live token with the current global stream | ||
token. Specifying a `room_id` causes it to return a historic token with | ||
the room specific topological token. | ||
""" | ||
"""Returns the current position of the rooms stream (historic token).""" | ||
stream_ordering = self.get_room_max_stream_ordering() | ||
if room_id is None: | ||
return RoomStreamToken(None, stream_ordering) | ||
else: | ||
topo = await self.db_pool.runInteraction( | ||
"_get_max_topological_txn", self._get_max_topological_txn, room_id | ||
) | ||
return RoomStreamToken(topo, stream_ordering) | ||
topo = await self.db_pool.runInteraction( | ||
"_get_max_topological_txn", self._get_max_topological_txn, room_id | ||
) | ||
return RoomStreamToken(topo, stream_ordering) | ||
|
||
def get_stream_id_for_event_txn( | ||
self, | ||
|
@@ -870,7 +862,11 @@ def _get_max_topological_txn(self, txn: LoggingTransaction, room_id: str) -> int | |
) | ||
|
||
rows = txn.fetchall() | ||
return rows[0][0] if rows else 0 | ||
# An aggregate function like MAX() will always return one row per group | ||
# so we can safely rely on the lookup here. For example, when a we | ||
# lookup a `room_id` which does not exist, `rows` will look like | ||
# `[(None,)]` | ||
return rows[0][0] if rows[0][0] is not None else 0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even though this function was annotated to always return Now we properly fallback to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. great spot, thanks! |
||
|
||
@staticmethod | ||
def _set_before_and_after( | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.