diff options
author | Patrick Cloke <clokep@users.noreply.github.com> | 2020-09-02 07:59:39 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-02 07:59:39 -0400 |
commit | 9356656e67ba6ed23f8f43d03fedaf559241aa84 (patch) | |
tree | 09cae3c2b6049caad5e521f3ba27ce8b0e2e1617 /synapse/storage | |
parent | Convert the main methods run by the reactor to async. (#8213) (diff) | |
download | synapse-9356656e67ba6ed23f8f43d03fedaf559241aa84.tar.xz |
Do not try to store invalid data in the stats table (#8226)
Diffstat (limited to 'synapse/storage')
-rw-r--r-- | synapse/storage/databases/main/stats.py | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/synapse/storage/databases/main/stats.py b/synapse/storage/databases/main/stats.py index 9b9bc304a8..55a250ef06 100644 --- a/synapse/storage/databases/main/stats.py +++ b/synapse/storage/databases/main/stats.py @@ -224,14 +224,32 @@ class StatsStore(StateDeltasStore): ) async def update_room_state(self, room_id: str, fields: Dict[str, Any]) -> None: - """ + """Update the state of a room. + + fields can contain the following keys with string values: + * join_rules + * history_visibility + * encryption + * name + * topic + * avatar + * canonical_alias + + A is_federatable key can also be included with a boolean value. + Args: - room_id - fields + room_id: The room ID to update the state of. + fields: The fields to update. This can include a partial list of the + above fields to only update some room information. """ - - # For whatever reason some of the fields may contain null bytes, which - # postgres isn't a fan of, so we replace those fields with null. + # Ensure that the values to update are valid, they should be strings and + # not contain any null bytes. + # + # Invalid data gets overwritten with null. + # + # Note that a missing value should not be overwritten (it keeps the + # previous value). + sentinel = object() for col in ( "join_rules", "history_visibility", @@ -241,8 +259,8 @@ class StatsStore(StateDeltasStore): "avatar", "canonical_alias", ): - field = fields.get(col) - if field and "\0" in field: + field = fields.get(col, sentinel) + if field is not sentinel and (not isinstance(field, str) or "\0" in field): fields[col] = None await self.db_pool.simple_upsert( |