mirror of
https://github.com/zulip/zulip.git
synced 2025-11-14 19:06:09 +00:00
reactions: Fix buggy migration for realm emoji.
The original implementation of this migration had a highly unfortunate bug that would result in it deleting all reactions to realm emoji on the server; we missed this in review, so essentially all historical realm emoji reactions on chat.zulip.org were lost :(. We both correct the problem, and also add logging of the deleted rows that would help should anything be deleted erroneously.
This commit is contained in:
@@ -14,7 +14,7 @@ def realm_emoji_name_to_id(apps: StateApps, schema_editor: DatabaseSchemaEditor)
|
|||||||
RealmEmoji = apps.get_model('zerver', 'RealmEmoji')
|
RealmEmoji = apps.get_model('zerver', 'RealmEmoji')
|
||||||
realm_emoji_by_realm_id = defaultdict(dict) # type: Dict[int, Dict[str, Any]]
|
realm_emoji_by_realm_id = defaultdict(dict) # type: Dict[int, Dict[str, Any]]
|
||||||
for realm_emoji in RealmEmoji.objects.all():
|
for realm_emoji in RealmEmoji.objects.all():
|
||||||
realm_emoji_by_realm_id[realm_emoji.realm_id] = {
|
realm_emoji_by_realm_id[realm_emoji.realm_id][realm_emoji.name] = {
|
||||||
'id': str(realm_emoji.id),
|
'id': str(realm_emoji.id),
|
||||||
'name': realm_emoji.name,
|
'name': realm_emoji.name,
|
||||||
'deactivated': realm_emoji.deactivated,
|
'deactivated': realm_emoji.deactivated,
|
||||||
@@ -27,6 +27,8 @@ def realm_emoji_name_to_id(apps: StateApps, schema_editor: DatabaseSchemaEditor)
|
|||||||
# Realm emoji used in this reaction has been deleted so this
|
# Realm emoji used in this reaction has been deleted so this
|
||||||
# reaction should also be deleted. We don't need to reverse
|
# reaction should also be deleted. We don't need to reverse
|
||||||
# this step in migration reversal code.
|
# this step in migration reversal code.
|
||||||
|
print("Reaction for (%s, %s) refers to deleted custom emoji %s; deleting" %
|
||||||
|
(emoji_name, reaction.message_id, reaction.user_profile_id))
|
||||||
reaction.delete()
|
reaction.delete()
|
||||||
else:
|
else:
|
||||||
reaction.emoji_code = realm_emoji["id"]
|
reaction.emoji_code = realm_emoji["id"]
|
||||||
|
|||||||
Reference in New Issue
Block a user