From ebfae283bd6a6754342e3d8581feefa461b08dbd Mon Sep 17 00:00:00 2001 From: Michael Brewer Date: Fri, 11 Feb 2022 11:32:33 -0800 Subject: [PATCH 1/2] fix(batch): clear exceptions for consistency closes #1021 --- aws_lambda_powertools/utilities/batch/base.py | 1 + 1 file changed, 1 insertion(+) diff --git a/aws_lambda_powertools/utilities/batch/base.py b/aws_lambda_powertools/utilities/batch/base.py index 21b59328ef0..bccaccb4615 100644 --- a/aws_lambda_powertools/utilities/batch/base.py +++ b/aws_lambda_powertools/utilities/batch/base.py @@ -351,6 +351,7 @@ def _prepare(self): """ self.success_messages.clear() self.fail_messages.clear() + self.exceptions.clear() self.batch_response = copy.deepcopy(self.DEFAULT_RESPONSE) def _process_record(self, record: dict) -> Union[SuccessResponse, FailureResponse]: From 0475b5de6c90e96842a013b89f4f216fe6afe379 Mon Sep 17 00:00:00 2001 From: Michael Brewer Date: Fri, 11 Feb 2022 11:41:57 -0800 Subject: [PATCH 2/2] tests(batch): Add failing test for warm starts --- tests/functional/test_utilities_batch.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tests/functional/test_utilities_batch.py b/tests/functional/test_utilities_batch.py index 2d9e6bab612..a5e1e706437 100644 --- a/tests/functional/test_utilities_batch.py +++ b/tests/functional/test_utilities_batch.py @@ -895,8 +895,16 @@ def test_batch_processor_error_when_entire_batch_fails(sqs_event_factory, record def lambda_handler(event, context): return processor.response() - # WHEN/THEN + # WHEN calling `lambda_handler` in cold start with pytest.raises(BatchProcessingError) as e: lambda_handler(event, {}) - ret = str(e) - assert ret is not None + + # THEN raise BatchProcessingError + assert "All records failed processing. " in str(e.value) + + # WHEN calling `lambda_handler` in warm start + with pytest.raises(BatchProcessingError) as e: + lambda_handler(event, {}) + + # THEN raise BatchProcessingError + assert "All records failed processing. " in str(e.value)