From 873bc9cf1a4fd253c77a9792384c926c5549b18d Mon Sep 17 00:00:00 2001 From: amlodzianowski Date: Thu, 24 Aug 2023 10:46:03 -0700 Subject: [PATCH] fix: broad catch statement for failedInvalidDelay (#6721) Co-authored-by: Adrian Mlodzianowski --- moto/sqs/models.py | 7 +++++-- tests/test_sqs/test_sqs.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/moto/sqs/models.py b/moto/sqs/models.py index f9abd81b2..06c27f7fd 100644 --- a/moto/sqs/models.py +++ b/moto/sqs/models.py @@ -912,8 +912,11 @@ class SQSBackend(BaseBackend): ) message.user_id = entry["Id"] # type: ignore[attr-defined] messages.append(message) - except InvalidParameterValue: - failedInvalidDelay.append(entry) + except InvalidParameterValue as err: + if "DelaySeconds is invalid" in str(err): + failedInvalidDelay.append(entry) + else: + raise err return messages, failedInvalidDelay diff --git a/tests/test_sqs/test_sqs.py b/tests/test_sqs/test_sqs.py index eec03ecbe..d8fa7c5b4 100644 --- a/tests/test_sqs/test_sqs.py +++ b/tests/test_sqs/test_sqs.py @@ -3273,3 +3273,37 @@ def test_fifo_dedupe_error_no_message_dedupe_id(): "The queue should either have ContentBasedDeduplication enabled " "or MessageDeduplicationId provided explicitly" ) + + +@mock_sqs +def test_fifo_dedupe_error_no_message_dedupe_id_batch(): + client = boto3.client("sqs", region_name="us-east-1") + response = client.create_queue( + QueueName=f"{str(uuid4())[0:6]}.fifo", Attributes={"FifoQueue": "true"} + ) + queue_url = response["QueueUrl"] + with pytest.raises(ClientError) as exc: + client.send_message_batch( + QueueUrl=queue_url, + Entries=[ + { + "Id": "id_1", + "MessageBody": "body_1", + "DelaySeconds": 0, + "MessageGroupId": "message_group_id_1", + "MessageDeduplicationId": "message_deduplication_id_1", + }, + { + "Id": "id_2", + "MessageBody": "body_2", + "DelaySeconds": 0, + "MessageGroupId": "message_group_id_2", + }, + ], + ) + + assert exc.value.response["Error"]["Code"] == "InvalidParameterValue" + assert exc.value.response["Error"]["Message"] == ( + "The queue should either have ContentBasedDeduplication enabled " + "or MessageDeduplicationId provided explicitly" + )