* Fix #3996 * Don't delete any message when duplicate handles
This commit is contained in:
parent
05cdcbcedc
commit
00be464c05
2 changed files with 47 additions and 4 deletions
|
|
@ -17,6 +17,7 @@ from .exceptions import (
|
|||
InvalidAttributeName,
|
||||
MessageNotInflight,
|
||||
ReceiptHandleIsInvalid,
|
||||
BatchEntryIdsNotDistinct,
|
||||
)
|
||||
from .models import sqs_backends
|
||||
from .utils import parse_message_attributes, extract_input_message_attributes
|
||||
|
|
@ -330,7 +331,8 @@ class SQSResponse(BaseResponse):
|
|||
"""
|
||||
queue_name = self._get_queue_name()
|
||||
|
||||
message_ids = []
|
||||
receipts = []
|
||||
|
||||
for index in range(1, 11):
|
||||
# Loop through looking for messages
|
||||
receipt_key = "DeleteMessageBatchRequestEntry.{0}.ReceiptHandle".format(
|
||||
|
|
@ -341,12 +343,25 @@ class SQSResponse(BaseResponse):
|
|||
# Found all messages
|
||||
break
|
||||
|
||||
self.sqs_backend.delete_message(queue_name, receipt_handle[0])
|
||||
|
||||
message_user_id_key = "DeleteMessageBatchRequestEntry.{0}.Id".format(index)
|
||||
message_user_id = self.querystring.get(message_user_id_key)[0]
|
||||
message_ids.append(message_user_id)
|
||||
receipts.append(
|
||||
{"receipt_handle": receipt_handle[0], "msg_user_id": message_user_id}
|
||||
)
|
||||
|
||||
receipt_seen = set()
|
||||
for receipt_and_id in receipts:
|
||||
receipt = receipt_and_id["receipt_handle"]
|
||||
if receipt in receipt_seen:
|
||||
raise BatchEntryIdsNotDistinct(receipt_and_id["msg_user_id"])
|
||||
receipt_seen.add(receipt)
|
||||
|
||||
for receipt_and_id in receipts:
|
||||
self.sqs_backend.delete_message(
|
||||
queue_name, receipt_and_id["receipt_handle"]
|
||||
)
|
||||
|
||||
message_ids = [r["msg_user_id"] for r in receipts]
|
||||
template = self.response_template(DELETE_MESSAGE_BATCH_RESPONSE)
|
||||
return template.render(message_ids=message_ids)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue