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

Commit

Permalink
Fix exception when using MSC3030 to look for remote federated events …
Browse files Browse the repository at this point in the history
…before room creation (#13197)

Complement tests: matrix-org/complement#405

This happens when you have some messages imported before the room is created.
Then use MSC3030 to look backwards before the room creation from a remote
federated server. The server won't find anything locally, but will ask over
federation which will have the remote event. The previous logic would
choke on not having the local event assigned.

```
Failed to fetch /timestamp_to_event from hs2 because of exception(UnboundLocalError) local variable 'local_event' referenced before assignment args=("local variable 'local_event' referenced before assignment",)
```
  • Loading branch information
MadLittleMods authored Jul 7, 2022
1 parent 0c95313 commit a962c5a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog.d/13197.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix exception when using experimental [MSC3030](https://github.com/matrix-org/matrix-spec-proposals/pull/3030) `/timestamp_to_event` endpoint to look for remote federated imported events before room creation.
6 changes: 5 additions & 1 deletion synapse/handlers/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -1375,6 +1375,7 @@ async def get_event_for_timestamp(
# the timestamp given and the event we were able to find locally
is_event_next_to_backward_gap = False
is_event_next_to_forward_gap = False
local_event = None
if local_event_id:
local_event = await self.store.get_event(
local_event_id, allow_none=False, allow_rejected=False
Expand Down Expand Up @@ -1461,7 +1462,10 @@ async def get_event_for_timestamp(
ex.args,
)

if not local_event_id:
# To appease mypy, we have to add both of these conditions to check for
# `None`. We only expect `local_event` to be `None` when
# `local_event_id` is `None` but mypy isn't as smart and assuming as us.
if not local_event_id or not local_event:
raise SynapseError(
404,
"Unable to find event from %s in direction %s" % (timestamp, direction),
Expand Down

0 comments on commit a962c5a

Please sign in to comment.