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

Commit

Permalink
Add an assertion on prev_events in create_new_client_event (#8041)
Browse files Browse the repository at this point in the history
I think this would have caught all the cases in
#7642 - and I think a 500 makes
more sense here than a 403
  • Loading branch information
richvdh committed Aug 10, 2020
1 parent cdbb8e6 commit fcbab08
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog.d/8041.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add an assertion on prev_events in create_new_client_event.
9 changes: 9 additions & 0 deletions synapse/handlers/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,15 @@ async def create_new_client_event(
else:
prev_event_ids = await self.store.get_prev_events_for_room(builder.room_id)

# we now ought to have some prev_events (unless it's a create event).
#
# do a quick sanity check here, rather than waiting until we've created the
# event and then try to auth it (which fails with a somewhat confusing "No
# create event in auth events")
assert (
builder.type == EventTypes.Create or len(prev_event_ids) > 0
), "Attempting to create an event with no prev_events"

event = await builder.build(prev_event_ids=prev_event_ids)
context = await self.state.compute_event_context(event)
if requester:
Expand Down
4 changes: 4 additions & 0 deletions tests/storage/test_redaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ def build(self, prev_event_ids):
def room_id(self):
return self._base_builder.room_id

@property
def type(self):
return self._base_builder.type

event_1, context_1 = self.get_success(
self.event_creation_handler.create_new_client_event(
EventIdManglingBuilder(
Expand Down

0 comments on commit fcbab08

Please sign in to comment.