From 5536ddba754fcdd65f8286c75829bf7860a393a5 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Fri, 8 Mar 2019 15:05:32 +0000 Subject: [PATCH 1/3] Make `prev_state` field optional The `prev_state` field on events is not specced and so synapse shouldn't explode if an event is missing the field. Fixes #4787 --- synapse/events/__init__.py | 1 - synapse/storage/events.py | 15 --------------- 2 files changed, 16 deletions(-) diff --git a/synapse/events/__init__.py b/synapse/events/__init__.py index bd130f881..fafa13518 100644 --- a/synapse/events/__init__.py +++ b/synapse/events/__init__.py @@ -141,7 +141,6 @@ class EventBase(object): origin = _event_dict_property("origin") origin_server_ts = _event_dict_property("origin_server_ts") prev_events = _event_dict_property("prev_events") - prev_state = _event_dict_property("prev_state") redacts = _event_dict_property("redacts") room_id = _event_dict_property("room_id") sender = _event_dict_property("sender") diff --git a/synapse/storage/events.py b/synapse/storage/events.py index 990a5eaaa..428300ea0 100644 --- a/synapse/storage/events.py +++ b/synapse/storage/events.py @@ -1407,21 +1407,6 @@ class EventsStore(StateGroupWorkerStore, EventFederationStore, EventsWorkerStore values=state_values, ) - self._simple_insert_many_txn( - txn, - table="event_edges", - values=[ - { - "event_id": event.event_id, - "prev_event_id": prev_id, - "room_id": event.room_id, - "is_state": True, - } - for event, _ in state_events_and_contexts - for prev_id, _ in event.prev_state - ], - ) - # Prefill the event cache self._add_to_cache(txn, events_and_contexts) From cac4723afe9d805b5d2906665fafffaef5d3e1a9 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Fri, 8 Mar 2019 15:08:34 +0000 Subject: [PATCH 2/3] Newsfile --- changelog.d/4837.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/4837.bugfix diff --git a/changelog.d/4837.bugfix b/changelog.d/4837.bugfix new file mode 100644 index 000000000..989aeb82b --- /dev/null +++ b/changelog.d/4837.bugfix @@ -0,0 +1 @@ +Fix bug where synapse expected an un-specced `prev_state` field on state events. From fe6c12e6cdbc2b34e93f6211c51e1eab33ae00c8 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Fri, 8 Mar 2019 16:38:23 +0000 Subject: [PATCH 3/3] Add comment to schema --- synapse/storage/schema/full_schemas/11/event_edges.sql | 2 ++ 1 file changed, 2 insertions(+) diff --git a/synapse/storage/schema/full_schemas/11/event_edges.sql b/synapse/storage/schema/full_schemas/11/event_edges.sql index 52eec8835..bccd1c6f7 100644 --- a/synapse/storage/schema/full_schemas/11/event_edges.sql +++ b/synapse/storage/schema/full_schemas/11/event_edges.sql @@ -37,6 +37,8 @@ CREATE TABLE IF NOT EXISTS event_edges( event_id TEXT NOT NULL, prev_event_id TEXT NOT NULL, room_id TEXT NOT NULL, + -- We no longer insert prev_state into this table, so all new rows will have + -- is_state as false. is_state BOOL NOT NULL, UNIQUE (event_id, prev_event_id, room_id, is_state) );