diff --git a/changelog.d/18593.bugfix b/changelog.d/18593.bugfix new file mode 100644 index 0000000000..9079b9534a --- /dev/null +++ b/changelog.d/18593.bugfix @@ -0,0 +1 @@ +Fix `avatar_url` and `displayname` being sent on federation profile queries when they are not set. \ No newline at end of file diff --git a/synapse/handlers/profile.py b/synapse/handlers/profile.py index cdc388b4ab..76aa90e11b 100644 --- a/synapse/handlers/profile.py +++ b/synapse/handlers/profile.py @@ -539,11 +539,17 @@ class ProfileHandler: response: JsonDict = {} try: if just_field is None or just_field == ProfileFields.DISPLAYNAME: - response["displayname"] = await self.store.get_profile_displayname(user) - + displayname = await self.store.get_profile_displayname(user) + # do not set the displayname field if it is None, + # since then we send a null in the JSON response + if displayname is not None: + response["displayname"] = displayname if just_field is None or just_field == ProfileFields.AVATAR_URL: - response["avatar_url"] = await self.store.get_profile_avatar_url(user) - + avatar_url = await self.store.get_profile_avatar_url(user) + # do not set the avatar_url field if it is None, + # since then we send a null in the JSON response + if avatar_url is not None: + response["avatar_url"] = avatar_url if self.hs.config.experimental.msc4133_enabled: if just_field is None: response.update(await self.store.get_profile_fields(user))