From 4267dcbb68db448bacbc0ec406f20e49b3a93503 Mon Sep 17 00:00:00 2001 From: rahuldeve Date: Mon, 25 Jul 2016 01:33:22 +0530 Subject: [PATCH] Change the way referred attachments are removed on message update. This fixes incorrect behavior when two or more attachments are removed in the same message. --- zerver/lib/actions.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py index 67e5bec52c..e8fc2bb6bd 100644 --- a/zerver/lib/actions.py +++ b/zerver/lib/actions.py @@ -3344,14 +3344,7 @@ def check_attachment_reference_change(prev_content, message): path_ids.append(path_id) attachments_to_update = Attachment.objects.filter(path_id__in=path_ids).select_for_update() - for attachment in attachments_to_update: - try: - attachment = Attachment.objects.get(path_id=path_id) - attachment.messages.remove(message) - attachment.save() - except Attachment.DoesNotExist: - # The entry for this attachment does not exist. Just ignore. - pass + message.attachment_set.remove(*attachments_to_update) to_add = list(new_attachments - prev_attachments) if len(to_add) > 0: