summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--changelog.d/8041.misc1
-rw-r--r--synapse/handlers/message.py9
-rw-r--r--tests/storage/test_redaction.py4
3 files changed, 14 insertions, 0 deletions
diff --git a/changelog.d/8041.misc b/changelog.d/8041.misc
new file mode 100644
index 0000000000..eefa98d744
--- /dev/null
+++ b/changelog.d/8041.misc
@@ -0,0 +1 @@
+Add an assertion on prev_events in create_new_client_event.
diff --git a/synapse/handlers/message.py b/synapse/handlers/message.py
index 708533d4d1..8ddded8389 100644
--- a/synapse/handlers/message.py
+++ b/synapse/handlers/message.py
@@ -768,6 +768,15 @@ class EventCreationHandler(object):
         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:
diff --git a/tests/storage/test_redaction.py b/tests/storage/test_redaction.py
index 41511d479f..1ea35d60c1 100644
--- a/tests/storage/test_redaction.py
+++ b/tests/storage/test_redaction.py
@@ -251,6 +251,10 @@ class RedactionTestCase(unittest.HomeserverTestCase):
             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(