diff --git a/moto/sqs/models.py b/moto/sqs/models.py index 12d88e661..3d9cd562c 100644 --- a/moto/sqs/models.py +++ b/moto/sqs/models.py @@ -845,7 +845,7 @@ class SQSBackend(BaseBackend): self._validate_message(queue, message_body, deduplication_id, group_id) - if delay_seconds: + if delay_seconds is not None: delay_seconds = int(delay_seconds) else: delay_seconds = queue.delay_seconds # type: ignore diff --git a/moto/sqs/responses.py b/moto/sqs/responses.py index 458a3bb0d..23c2dc84e 100644 --- a/moto/sqs/responses.py +++ b/moto/sqs/responses.py @@ -308,7 +308,7 @@ class SQSResponse(BaseResponse): @jsonify_error def send_message(self) -> Union[str, TYPE_RESPONSE]: message = self._get_param("MessageBody") - delay_seconds = int(self._get_param("DelaySeconds", 0)) + delay_seconds = self._get_param("DelaySeconds") message_group_id = self._get_param("MessageGroupId") message_dedupe_id = self._get_param("MessageDeduplicationId") diff --git a/tests/test_sqs/test_sqs.py b/tests/test_sqs/test_sqs.py index a28e0428e..6b8d4f67d 100644 --- a/tests/test_sqs/test_sqs.py +++ b/tests/test_sqs/test_sqs.py @@ -1438,6 +1438,19 @@ def test_send_message_with_delay(): assert len(messages) == 0 +@mock_aws +def test_send_message_with_message_delay_overriding_queue_delay(): + sqs = boto3.client("sqs", region_name="us-east-1") + name = str(uuid4())[0:6] + # By default, all messages on this queue are delayed + resp = sqs.create_queue(QueueName=name, Attributes={"DelaySeconds": "10"}) + queue_url = resp["QueueUrl"] + # But this particular message should have no delay + sqs.send_message(QueueUrl=queue_url, MessageBody="test", DelaySeconds=0) + resp = sqs.receive_message(QueueUrl=queue_url, MaxNumberOfMessages=10) + assert len(resp["Messages"]) == 1 + + @mock_aws def test_send_large_message_fails(): sqs = boto3.resource("sqs", region_name="us-east-1")