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

Fix bug which caused failure on join with malformed membership events #8385

Merged
merged 1 commit into from
Sep 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/8385.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a bug which could cause errors in rooms with malformed membership events, on servers using sqlite.
10 changes: 7 additions & 3 deletions synapse/storage/databases/main/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import itertools
import logging
from collections import OrderedDict, namedtuple
from typing import TYPE_CHECKING, Dict, Iterable, List, Set, Tuple
from typing import TYPE_CHECKING, Any, Dict, Iterable, List, Optional, Set, Tuple

import attr
from prometheus_client import Counter
Expand Down Expand Up @@ -1108,6 +1108,10 @@ def _store_event_reference_hashes_txn(self, txn, events):
def _store_room_members_txn(self, txn, events, backfilled):
"""Store a room member in the database.
"""

def str_or_none(val: Any) -> Optional[str]:
return val if isinstance(val, str) else None

self.db_pool.simple_insert_many_txn(
txn,
table="room_memberships",
Expand All @@ -1118,8 +1122,8 @@ def _store_room_members_txn(self, txn, events, backfilled):
"sender": event.user_id,
"room_id": event.room_id,
"membership": event.membership,
"display_name": event.content.get("displayname", None),
"avatar_url": event.content.get("avatar_url", None),
"display_name": str_or_none(event.content.get("displayname")),
"avatar_url": str_or_none(event.content.get("avatar_url")),
}
for event in events
],
Expand Down