From b3d344c0dab33f695864c52d8ceee9bd02928d53 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Mon, 30 Dec 2019 21:43:59 +0000 Subject: [PATCH] hacks to work around #6605 --- synapse/state/v2.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/synapse/state/v2.py b/synapse/state/v2.py index cb77ed5b781d..6510d351d6ba 100644 --- a/synapse/state/v2.py +++ b/synapse/state/v2.py @@ -183,16 +183,16 @@ def _get_power_level_for_sender(room_id, event_id, event_map, state_res_store): pl = None for aid in event.auth_event_ids(): - aev = yield _get_event(room_id, aid, event_map, state_res_store) - if (aev.type, aev.state_key) == (EventTypes.PowerLevels, ""): + aev = yield _get_event(room_id, aid, event_map, state_res_store, allow_none=True) + if aev and (aev.type, aev.state_key) == (EventTypes.PowerLevels, ""): pl = aev break if pl is None: # Couldn't find power level. Check if they're the creator of the room for aid in event.auth_event_ids(): - aev = yield _get_event(room_id, aid, event_map, state_res_store) - if (aev.type, aev.state_key) == (EventTypes.Create, ""): + aev = yield _get_event(room_id, aid, event_map, state_res_store, allow_none=True) + if aev and (aev.type, aev.state_key) == (EventTypes.Create, ""): if aev.content.get("creator") == event.sender: return 100 break @@ -403,9 +403,9 @@ def _iterative_auth_checks( auth_events = {} for aid in event.auth_event_ids(): - ev = yield _get_event(room_id, aid, event_map, state_res_store) + ev = yield _get_event(room_id, aid, event_map, state_res_store, allow_none=True) - if ev.rejected_reason is None: + if ev and ev.rejected_reason is None: auth_events[(ev.type, ev.state_key)] = ev for key in event_auth.auth_types_for_event(event): @@ -516,7 +516,7 @@ def _get_mainline_depth_for_event(event, mainline_map, event_map, state_res_stor @defer.inlineCallbacks -def _get_event(room_id, event_id, event_map, state_res_store): +def _get_event(room_id, event_id, event_map, state_res_store, allow_none=False): """Helper function to look up event in event_map, falling back to looking it up in the store @@ -532,7 +532,9 @@ def _get_event(room_id, event_id, event_map, state_res_store): if event_id not in event_map: events = yield state_res_store.get_events([event_id], allow_rejected=True) event_map.update(events) - event = event_map[event_id] + event = event_map.get(event_id) + if allow_none and event is None: + return None assert event is not None if event.room_id != room_id: raise Exception(