diff options
author | David Robertson <davidr@element.io> | 2022-05-17 13:48:19 +0100 |
---|---|---|
committer | David Robertson <davidr@element.io> | 2022-05-17 13:55:58 +0100 |
commit | a1adede4445a60e3476a0d8f247427c453114078 (patch) | |
tree | c77ad66cfb49ad7de6966658ae0b7abcc62b2712 | |
parent | Move non_null_str_or_none to s.utils.stringutils (diff) | |
download | synapse-a1adede4445a60e3476a0d8f247427c453114078.tar.xz |
discard strings with nulls before user dir update
-rw-r--r-- | synapse/storage/databases/main/user_directory.py | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/synapse/storage/databases/main/user_directory.py b/synapse/storage/databases/main/user_directory.py index df772d4721..028db69af3 100644 --- a/synapse/storage/databases/main/user_directory.py +++ b/synapse/storage/databases/main/user_directory.py @@ -29,6 +29,7 @@ from typing import ( from typing_extensions import TypedDict from synapse.api.errors import StoreError +from synapse.util.stringutils import non_null_str_or_none if TYPE_CHECKING: from synapse.server import HomeServer @@ -469,11 +470,9 @@ class UserDirectoryBackgroundUpdateStore(StateDeltasStore): """ Update or add a user's profile in the user directory. """ - # If the display name or avatar URL are unexpected types, overwrite them. - if not isinstance(display_name, str): - display_name = None - if not isinstance(avatar_url, str): - avatar_url = None + # If the display name or avatar URL are unexpected types, replace with None. + display_name = non_null_str_or_none(display_name) + avatar_url = non_null_str_or_none(avatar_url) def _update_profile_in_user_dir_txn(txn: LoggingTransaction) -> None: self.db_pool.simple_upsert_txn( |