Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQS - Improve delete_message_batch() error responses #4765

Merged
merged 1 commit into from
Jan 15, 2022

Conversation

sjakthol
Copy link
Contributor

Currently, if the input to SQS.delete_message_batch() includes an invalid receipt handle, moto returns an error:

Traceback (most recent call last):
  File "test.py", line 26, in <module>
    sqs.delete_message_batch(
  File "<...>/botocore/client.py", line 391, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "<...>/botocore/client.py", line 719, in _make_api_call
    raise error_class(parsed_response, operation_name)
botocore.errorfactory.ReceiptHandleIsInvalid: An error occurred (ReceiptHandleIsInvalid) when calling the DeleteMessageBatch operation: The input receipt handle is invalid.

However, if the input to Amazon SQS DeleteMessageBatch API includes an invalid receipt handle, the Amazon SQS API returns the error in Failed field of an 200 OK response:

{
  "Successful": [...],
  "Failed": [{
    "Id": "invalid",
    "SenderFault": True,
    "Code": "ReceiptHandleIsInvalid",
    "Message": 'The input receipt handle "invalid" is not a valid receipt handle.',
  }],
  "ResponseMetadata": {...},
}

This commit updates moto delete_message_batch() method implementation to return ReceiptHandleIsInvalid errors in the "Failed" field of a 200 OK response instead of failing the entire request.

The implementation follows the implementation of similar functionality in the SQS change_message_visibility_batch() method. Test case added to check output in case of a partial failure.

Currently, if the input to SQS.delete_message_batch() includes an
invalid receipt handle, moto returns an error:

```
Traceback (most recent call last):
  File "test.py", line 26, in <module>
    sqs.delete_message_batch(
  File "<...>/botocore/client.py", line 391, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "<...>/botocore/client.py", line 719, in _make_api_call
    raise error_class(parsed_response, operation_name)
botocore.errorfactory.ReceiptHandleIsInvalid: An error occurred (ReceiptHandleIsInvalid) when calling the DeleteMessageBatch operation: The input receipt handle is invalid.
```

However, if the input to Amazon SQS DeleteMessageBatch API includes an
invalid receipt handle, the Amazon SQS API returns the error in Failed
field of an 200 OK response:

```
{
  "Successful": [...],
  "Failed": [{
    "Id": "invalid",
    "SenderFault": True,
    "Code": "ReceiptHandleIsInvalid",
    "Message": 'The input receipt handle "invalid" is not a valid receipt handle.',
  }],
  "ResponseMetadata": {...},
}
```

This commit updates moto delete_message_batch() method implementation
to return ReceiptHandleIsInvalid errors in the "Failed" field of a
200 OK response instead of failing the entire request.

The implementation follows the implementation of similar functionality
in the SQS change_message_visibility_batch() method. Test case added
to check output in case of a partial failure.
@codecov-commenter
Copy link

Codecov Report

Merging #4765 (3ca4be2) into master (8f63ce0) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4765      +/-   ##
==========================================
- Coverage   95.38%   95.38%   -0.01%     
==========================================
  Files         575      575              
  Lines       61461    61466       +5     
==========================================
+ Hits        58626    58630       +4     
- Misses       2835     2836       +1     
Flag Coverage Δ
servertests 47.36% <0.00%> (-0.01%) ⬇️
test_responses 33.01% <0.00%> (-0.01%) ⬇️
unittests 95.27% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
moto/sqs/responses.py 94.82% <100.00%> (+0.09%) ⬆️
moto/awslambda/models.py 92.85% <0.00%> (-0.12%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8f63ce0...3ca4be2. Read the comment docs.

Copy link
Collaborator

@bblommers bblommers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for the fix @sjakthol

@bblommers bblommers merged commit ca327e3 into getmoto:master Jan 15, 2022
@bblommers bblommers added this to the 2.3.2 milestone Jan 15, 2022
@github-actions
Copy link
Contributor

This is now part of moto >= 2.3.2.dev12

@sjakthol sjakthol deleted the sqs-batch-delete-error-handling branch January 16, 2022 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants