diff --git a/moto/sqs/models.py b/moto/sqs/models.py index f2e3ed400..6779bc2b5 100644 --- a/moto/sqs/models.py +++ b/moto/sqs/models.py @@ -263,6 +263,9 @@ class Queue(BaseModel): if 'maxReceiveCount' not in self.redrive_policy: raise RESTError('InvalidParameterValue', 'Redrive policy does not contain maxReceiveCount') + # 'maxReceiveCount' is stored as int + self.redrive_policy['maxReceiveCount'] = int(self.redrive_policy['maxReceiveCount']) + for queue in sqs_backends[self.region].queues.values(): if queue.queue_arn == self.redrive_policy['deadLetterTargetArn']: self.dead_letter_queue = queue diff --git a/tests/test_sqs/test_sqs.py b/tests/test_sqs/test_sqs.py index d53ae50f7..56d82ea61 100644 --- a/tests/test_sqs/test_sqs.py +++ b/tests/test_sqs/test_sqs.py @@ -1117,6 +1117,28 @@ def test_redrive_policy_set_attributes(): assert copy_policy == redrive_policy +@mock_sqs +def test_redrive_policy_set_attributes_with_string_value(): + sqs = boto3.resource('sqs', region_name='us-east-1') + + queue = sqs.create_queue(QueueName='test-queue') + deadletter_queue = sqs.create_queue(QueueName='test-deadletter') + + queue.set_attributes(Attributes={ + 'RedrivePolicy': json.dumps({ + 'deadLetterTargetArn': deadletter_queue.attributes['QueueArn'], + 'maxReceiveCount': '1', + })}) + + copy = sqs.get_queue_by_name(QueueName='test-queue') + assert 'RedrivePolicy' in copy.attributes + copy_policy = json.loads(copy.attributes['RedrivePolicy']) + assert copy_policy == { + 'deadLetterTargetArn': deadletter_queue.attributes['QueueArn'], + 'maxReceiveCount': 1, + } + + @mock_sqs def test_receive_messages_with_message_group_id(): sqs = boto3.resource('sqs', region_name='us-east-1')