diff --git a/synapse/storage/databases/main/profile.py b/synapse/storage/databases/main/profile.py index 787964c1c1..3a28d1ec27 100644 --- a/synapse/storage/databases/main/profile.py +++ b/synapse/storage/databases/main/profile.py @@ -843,7 +843,7 @@ class ProfileWorkerStore(SQLBaseStore): # Record updates in the profile updates stream if ( field_name in (ProfileFields.DISPLAYNAME, ProfileFields.AVATAR_URL) - and new_value == "" + and new_value is None ): # Displayname and avatar_url are special in that they are deleted by # setting the value to an empty string. diff --git a/tests/handlers/test_profile.py b/tests/handlers/test_profile.py index 4b66be0102..3c2a8ef990 100644 --- a/tests/handlers/test_profile.py +++ b/tests/handlers/test_profile.py @@ -338,6 +338,8 @@ class ProfileTestCase(unittest.HomeserverTestCase): ), ) + # Set value to empty string. For displayname/avatar_url, this is basically + # a delete of the field. For other fields, it's a value. self.get_success( self.handler.set_field( target_user=self.frank, @@ -353,9 +355,14 @@ class ProfileTestCase(unittest.HomeserverTestCase): limit=1, ) ) + expected_action = ( + ProfileUpdateAction.DELETE.value + if field_name in (ProfileFields.DISPLAYNAME, ProfileFields.AVATAR_URL) + else ProfileUpdateAction.UPDATE.value + ) self.assertEqual( delete_updates[0], - (3, "@1234abcd:test", ProfileUpdateAction.UPDATE.value, {field_name}), + (3, "@1234abcd:test", expected_action, {field_name}), ) @override_config({"include_profile_updates_in_sync": True})